B - Moderate Differences


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.

Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:

  • For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).

As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares. Determine whether it is possible to fill the squares under the condition.

Constraints

  • 3≤N≤500000
  • 0≤A≤109
  • 0≤B≤109
  • 0≤CD≤109
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B C D

Output

Print YES if it is possible to fill the squares under the condition; print NO otherwise.


Sample Input 1

Copy
5 1 5 2 4

Sample Output 1

Copy
YES

For example, fill the squares with the following integers: 1−1375, from left to right.


Sample Input 2

Copy
4 7 6 4 5

Sample Output 2

Copy
NO

Sample Input 3

Copy
48792 105960835 681218449 90629745 90632170

Sample Output 3

Copy
NO

Sample Input 4

Copy
491995 412925347 825318103 59999126 59999339

Sample Output 4

Copy
YES

题意:告诉你n个空格,最左边和最右边的数字确定,相邻的空格数字之差(绝对值)在[c,d]范围内,问数字能不能全部添加在空格内
解法:
1 c<=xi+1-xi<=d -d<=xi+1-xi<=-c
2 ∑(xi+1-xi)=xN-xN-1+.....+x3-x2+x2-x1=xN-x1=b-a
3 如果有m个符合-d<=xi+1-xi<=-c 那么应该有n-m+1个符合c<=xi+1-xi<=d
那么 c(n-m+1)-dm<=∑(xi+1-xi)<=-cm+(n-m+1)d
---->c(n-m+1)-dm<=b-a<=-cm+(n-m+1)d
求存在m就行
 #include<bits/stdc++.h>
#define N 10005
#define LL long long
#define inf 1<<29
#define eps 1e-7
using namespace std;
long long n,a,b,c,d; int main(){
int flag=;
cin>>n>>a>>b>>c>>d;
for(int i=;i<n;i++){
if(c*(n--i)-d*i<=abs(b-a)&&-*c*(i)+(n--i)*d>=abs(b-a)){
flag=;
}
}
if(flag==){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
return ;
}

AtCoder Grand Contest 017 B的更多相关文章

  1. AtCoder Grand Contest 017 F - Zigzag

    题目传送门:https://agc017.contest.atcoder.jp/tasks/agc017_f 题目大意: 找出\(m\)个长度为\(n\)的二进制数,定义两个二进制数的大小关系如下:若 ...

  2. AtCoder Grand Contest 017 (VP)

    contest link Official Editorial 比赛体验--之前做题的时候感觉 AtCoder 挺快的,现在打了VP之后发现还是会挂的--而且不是加载缓慢或者载不出来,直接给你一个无法 ...

  3. AtCoder Grand Contest 017 题解

    A - Biscuits 题目: 给出 \(n\) 个物品,每个物品有一个权值. 问有多少种选取方式使得物品权值之和 \(\bmod\space 2\) 为 \(p\). \(n \leq 50\) ...

  4. AtCoder Grand Contest 017 迟到记

    晚上去操场上浪. 回来以后看到好几个人开着 \(AtCoder\) 在打代码. ... ... 今天有 \(AtCoder\) 比赛 ? 管它呢, \(Kito\) 在切西瓜,先吃西瓜... 然后看 ...

  5. AtCoder Grand Contest 017

    noi前橙名计划失败.全程搞C而gg…… A - Biscuits 题意:背包,求价值为奇/偶的方案数. #include<cstdio> #include<queue> #i ...

  6. 题解——ATCoder AtCoder Grand Contest 017 B - Moderate Differences(数学,构造)

    题面 B - Moderate Differences Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stat ...

  7. AtCoder Grand Contest 017 A

    Problem Statement There are N bags of biscuits. The i-th bag contains Ai biscuits. Takaki will selec ...

  8. AtCoder Grand Contest 017题解

    传送门 \(A\) 直接转移就是了 typedef long long ll; const int N=55; ll f[N][2];int a[N],n,p; int main(){ scanf(& ...

  9. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

随机推荐

  1. iOS开发 - App程序启动原理

    Info.plist和pch文件的作用 建立一个project后,会在Supporting files目录下看到一个"project名-Info.plist"的文件,该文件对pro ...

  2. eclipse配置android

    先在eclipse中安装ADT插件,install内点击add,name:ADT, URL:http://dl-ssl.google.com/android/eclipse/ 之后直接finish就好 ...

  3. 浅谈JavaScript的事件(事件对象)

    在触发DOM上的某个事件时,会产生一个事件对象event,这个对象中包含这所有与事件有关的信息.包括导致事件的元素.事件的类型和事件的相关信息.例如鼠标操作的事件中,会包含鼠标的位置信息.而键盘触发的 ...

  4. HDOJ1004 数组还要自己初始化

    #include <iostream> #include <stdio.h> #include "string.h"using namespace std; ...

  5. delphi中的HOOK [转贴]

    按事件分类,有如下的几种常用类型的钩子: 1)键盘钩子可以监视各种键盘消息. 2)鼠标钩子可以监视各种鼠标消息. 3)外壳钩子可以监视各种Shell事件消息. 4)日志钩子可以记录从系统消息队列中取出 ...

  6. 在VC中动态加载ODBC的方法

    在使用VC.VB.Delphi等高级语言编写数据库应用程序时,往往需要用户自己在控制面板中配置ODBC数据源.对于一般用户而言,配置ODBC数据源可能是一件比较困难的工作.而且,在实际应用中,用户往往 ...

  7. wx.request的并发问题

    wepyjs - 小程序组件化开发框架 https://tencent.github.io/wepy/document.html#/ 在同时并发10个request请求测试时: 不使用WePY: 使用 ...

  8. pyspark mongodb yarn

    from pyspark.sql import SparkSession my_spark = SparkSession \ .builder \ .appName("myApp" ...

  9. Android 返回键的处理

    多网友不明确怎样在Android平台上捕获Back键的事件.Back键是手机上的后退键,一般的软件不捕获相关信息可能导致你的程序被切换到后台.而回到桌面的尴尬情况,在Android上有两种方法来获取该 ...

  10. 数字和为sum的方法数(动态规划)

    题目描述 给定一个有n个正整数的数组A和一个整数sum,求选择数组A中部分数字和为sum的方案数.当两种选取方案有一个数字的下标不一样,我们就认为是不同的组成方案. 输入描述: 输入为两行: 第一行为 ...