首页 > 其他分享 >Cake Assembly Line

Cake Assembly Line

时间:2023-06-29 12:24:01浏览次数:27  
标签:cakes Assembly conveyor chocolate test example Cake Line line

Cake Assembly Line time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

A cake assembly line in a bakery was once again optimized, and now n cakes are made at a time! In the last step, each of the n cakes should be covered with chocolate.

Consider a side view on the conveyor belt, let it be a number line. The i-th cake occupies the segment [ai−w,ai+w][−,+] on this line, each pair of these segments does not have common points. Above the conveyor, there are n dispensers, and when a common button is pressed, chocolate from the i-th dispenser will cover the conveyor segment [bi−h,bi+h][−ℎ,+ℎ]. Each pair of these segments also does not have common points.

Cakes and dispensers corresponding to the first example.

The calibration of this conveyor belt part has not yet been performed, so you are to make it. Determine if it's possible to shift the conveyor so that each cake has some chocolate on it, and there is no chocolate outside the cakes. You can assume that the conveyour is long enough, so the cakes never fall. Also note that the button can only be pressed once.

In the first example we can shift the cakes as shown in the picture.
Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤1051≤≤105). The description of the test cases follows.

The first line of each test case contains three integers n, w, and hℎ (1≤n≤1051≤≤105; 1≤w,h≤1051≤,ℎ≤105; h≤wℎ≤) — the number of cakes and dispensers, as well as the halfwidths of cakes and segments on which the chocolate is dispensed.

The second line contains n integers a11, a22, ..., an (1≤ai≤1091≤≤109) — the positions of the cakes centers. It is guaranteed that ai+w<ai+1−w+<+1− for all i.

The third line contains n integers b11, b22, ..., bn (1≤bi≤1091≤≤109) — the positions of the dispensers. It is guaranteed that bi+h<bi+1−h+ℎ<+1−ℎ for all i.

It is guaranteed that the sum of n over all test cases does not exceed 105105.

Output

For each test case output "YES", if it's possible to shift the conveyor in such a way that each cake ends up with some chocolate, and no chocolate is outside the cakes, and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Example input Copy 4 3 10 5 65 95 165 40 65 145 5 2 1 1 6 11 16 21 4 9 14 19 24 3 3 2 13 22 29 5 16 25 4 4 1 27 36 127 136 35 50 141 144 output Copy
YES
YES
NO
YES
Note

The first example is shown in the figures in the statement.

In the second example, we can move the conveyor, for example, so that the centers of the cakes are at 4,9,14,19,244,9,14,19,24.

In the third example, we can't move the conveyor accordingly.

//设向右为正方向
//蛋糕如果需要移动到最右端点,那就是rb-ra
//最左端点的话就是lb-la
//蛋糕只需要向右移动{l,r}这个区间就是合法的
//对于每个蛋糕都有一个这样的区间,只需要判断每个区间是否都有交集就可以了
#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+10,mod=1e9+7;
string s;
long long n,t,a[N],b[N],res,num,ans,w,h,l=-1e9,r=1e9;
bool vis[N];
int main()
{
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n>>w>>h;
        l=-1e9,r=1e9;
        for(int i=0;i<n;i++) cin>>a[i];
        for(int i=0;i<n;i++) cin>>b[i];
        for(int i=0;i<n;i++){
            l=max(l,b[i]+h-a[i]-w),r=min(r,b[i]-h-a[i]+w);//判断是否有交集
            if(l>r){
                cout<<"NO"<<endl;
                goto nexts;
            }
        }
        cout<<"YES"<<endl;
        nexts:;
    }
    return 0;
}

 

标签:cakes,Assembly,conveyor,chocolate,test,example,Cake,Line,line
From: https://www.cnblogs.com/o-Sakurajimamai-o/p/17513875.html

相关文章

  • Online Temporal Calibration for Monocular Visual-Inertial Systems
    摘要:准确的状态估计是各种智能应用的基本模块,例如机器人导航、自动驾驶、虚拟和增强现实。近年来,视觉和惯性融合是一种流行的技术,用于6自由度状态估计。不同传感器测量记录的时间点对于系统的鲁棒性和准确性非常重要。实际上,每个传感器的时间戳通常会受到触发和传输延迟的影响,导......
  • 将 SmartAssembly 与单文件可执行文件一起使用 (.NET Core 6)
    .NETCore6引入了创建单文件可执行文件的功能。这只允许分发一个应用程序文件,因为所有配置和依赖项都包含在二进制文件本身中。该功能为依赖项嵌入提供了一种本机方法,这在发布生成数百个程序集的独立应用程序时最有益。它可用于依赖于框架或自包含的应用程序,但在这两种情况下都......
  • pipeline流水线脚本
    Pipeline流水线脚本pipeline{ agent{ label'slave1-apitest' } stages{ stage("拉取自动化测试代码"){ steps{ gitcredentialsId:'65623c68-96bc-4037-ab73-db5c091f358f',url:'https://gitee.com/huangshao1989/api-framework.git' ......
  • [数据结构]scanning line(扫描线)
    scanningline(扫描线)1.1扫描线的思想以及在几何问题上的应用(eg1,3)二维数点平面上有n个点(xi,yi)。回答q个询问,每个询问给定一个矩形[X1,X2]×[Y1,Y2],询问矩形里面有多少个点。因为有1e9的范围,我们离散化一下,我们只关心顺序,不关心具体是多少这里相当于只需要把原来的点的......
  • 强化学习从基础到进阶-常见问题和面试必知必答[5]::梯度策略、添加基线(baseline)、优势函
    强化学习从基础到进阶-常见问题和面试必知必答[5]::梯度策略、添加基线(baseline)、优势函数、动作分配合适的分数(credit)1.核心词汇策略(policy):在每一个演员中会有对应的策略,这个策略决定了演员的后续动作。具体来说,策略就是对于外界的输入,输出演员现在应该要执行的动作。一般地,我......
  • 强化学习从基础到进阶-常见问题和面试必知必答[5]::梯度策略、添加基线(baseline)、优势函
    强化学习从基础到进阶-常见问题和面试必知必答[5]::梯度策略、添加基线(baseline)、优势函数、动作分配合适的分数(credit)1.核心词汇策略(policy):在每一个演员中会有对应的策略,这个策略决定了演员的后续动作。具体来说,策略就是对于外界的输入,输出演员现在应该要执行的动作。一般地,我们......
  • 事务超时异常:org.springframework.transaction.TransactionTimedOutException: Transa
    报错如下:代码如下:Controllerimportcom.zwh.service.impl.TimeOutService;importlombok.extern.slf4j.Slf4j;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.GetMapping;importorg.springframework.w......
  • WebAssembly能不能取代JavaScript?15张卡通图给你答案!
    一切能用JavaScript实现的,终将用JavaScript实现。一切能编译为WebAssembly的,终将编译为WebAssembly。前端er们,WebAssembly用上了吗?在浏览器中快速运行非JavaScript语言,比如C、C++、Rust,是不是很香?今天,我们就来用15张小画图说WebAssembly。有必要先介绍一下小画的创作者。她叫LinCl......
  • Scrapy_ImagePipeline保存图片
    创建一个项目scrapystartprojectmyfrist(project_name)创建一个爬虫scrapygenspider爬虫名爬虫地址需要安装pillowpipinstallpillow报错:twisted.python.failure.FailureOpenSSL.SSL.Error解决方案pipuninstallcryptographypipinstallcryptography==36.0.2代......
  • 驱动开发:摘除InlineHook内核钩子
    在笔者上一篇文章《驱动开发:内核层InlineHook挂钩函数》中介绍了通过替换函数头部代码的方式实现Hook挂钩,对于ARK工具来说实现扫描与摘除InlineHook钩子也是最基本的功能,此类功能的实现一般可在应用层进行,而驱动层只需要保留一个读写字节的函数即可,将复杂的流程放在应用层实现是一......