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. nyoj 题目10 skiing —— 南阳oj

    题目信息例如以下: skiing 时间限制:3000 ms  |  内存限制:65535 KB 难度:5 描写叙述 Michael喜欢滑雪百这并不奇怪, 由于滑雪的确非常刺激.但是为了获得速度,滑的区 ...

  2. LiberOJ #6210. 「美团 CodeM 决赛」tree 树形DP

    题目链接:点这里 题解: 需要证明,所求的路径一定是全部权值都为1或者,路径上权值至多有一个为2其余为1且权值2在路径中央. 然后树形DP 设定dp[i][0/1] 以1为根的情况下,以i 节点下子树 ...

  3. intellij IDEA 更新java后不用重启tomcat

    最近项目大了,每次修改后重启都要等和很久,那个煎熬…… 为了解决这个问题,万能的Google  装了这个  JREBEL 5.63最新的 安装步骤: 一.IDEA在线搜索 jrebel  安装 二.破 ...

  4. 利用CoreTelephony获取用户当前网络状态(判断2G,3G,4G)

    前言: 在项目开发当中,往往需要利用网络.而用户的网络环境也需要我们开发者去注意,根据不同的网络状态作相应的优化,以提升用户体验. 但通常我们只会判断用户是在WIFI还是移动数据,而实际上,移动数据也 ...

  5. iOS 视图在不同View之间的切换(对于convertRect:函数的一些理解)

    可以通过以下函数完成坐标体系在不同View之间的切换,如下面是完成当前View向ParentView坐标的转换(一个矩阵转换)CGRect parentRect = [currentView conv ...

  6. 在docker里查看java进程

    先使用命令查看docker的运行进程 docker ps [root@localhost logs]# docker ps CONTAINER ID        IMAGE             ...

  7. POJ2195 Going Home —— 最大权匹配 or 最小费用最大流

    题目链接:https://vjudge.net/problem/POJ-2195 Going Home Time Limit: 1000MS   Memory Limit: 65536K Total ...

  8. YTU 2203: 最小节点(线性表)

    2203: 最小节点(线性表) 时间限制: 1 Sec  内存限制: 128 MB 提交: 243  解决: 204 题目描述 (线性表)设有一个由正整数组成的无序(向后)单链表,编写完成下列功能的算 ...

  9. codeforces 436A. Feed with Candy 解题报告

    题目链接:http://codeforces.com/contest/436/problem/A 题目意思:给出 n 颗只有两种类型:fruit 和 caramel的candies,这些candies ...

  10. NOI1995 石子合并

    传送门 这道题是经典的区间DP.因为它要求有每两个相邻的石子堆合并,所以很显然对于区间[l,r]内的情况,我们只要枚举端点k,之后把这左右两端的石子合并取最大/小即可. 之后,这题是环形怎么破?显然不 ...