AtCoder Grand Contest 017-B - Moderate Differences
2017-07-09 23:26
513 查看
B - Moderate Differences
Time limit : 2sec / Memory limit : 256MBScore : 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≤C≤D≤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
5 1 5 2 4
Sample Output 1
YES
For example, fill the squares with the following integers: 1, −1, 3, 7, 5, from left to right.
Sample Input 2
4 7 6 4 5
Sample Output 2
NO
Sample Input 3
48792 105960835 681218449 90629745 90632170
Sample Output 3
NO
Sample Input 4
491995 412925347 825318103 59999126 59999339
Sample Output 4
YES
题目大意:一行有n个方格,第一个中填入了一个数A,最后一个填入了一个数B,其他格子尚未填写,问是否存在一种填入方法,使得每两个格子中数字之差的绝对值在[C,D]区间中。
解题思路:详见editorial
#include<iostream> using namespace std; typedef long long LL; const int MAXN=105; LL n,a,b,c,d; int main() { while(cin>>n>>a>>b>>c>>d) { bool flag=false; for(int i=0;i<=n-1;i++) { if(c*(n-1-i)-d*i<=b-a&&(n-1-i)*d-c*i>=b-a) { flag=true; break; } } if(flag) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
相关文章推荐
- AtCoder Grand Contest 017 C - Snuke and Spells
- Atcoder Grand Contest 017 F Zigzag
- AtCoder Grand Contest 017 迟到记
- AtCoder Grand Contest 017 D - Game on Tree SG函数
- AtCoder Grand Contest 017-A - Biscuits
- AtCoder Grand Contest 017 A
- AtCoder Grand Contest 017 F - Zigzag 状压dp
- [AtCoder Grand Contest 017] F: Zigzag (agc017F)
- AtCoder Grand Contest 017 B
- AtCoder Grand Contest 017
- AtCoder Grand Contest 017 题解
- AtCoder Grand Contest 017-A Biscuits
- AtCoder Grand Contest 017 D - Game on Tree
- Atcoder Grand Contest 020D Min Max Repetition
- AtCoder Grand Contest 005 D - ~K Perm Counting 容斥原理+dp
- [AtCoder Grand Contest 071] E: Jigsaw (agc071E)
- AtCoder Grand Contest 012 A - AtCoder Group Contest(贪心)
- Atcoder Grand Contest 013C - Ants on a Circle
- *AtCoder Grand Contest 002F - Leftmost Ball
- AtCoder Grand Contest 011 E - Increasing Numbers(灵性乱搞)