AtCoder Grand Contest 017 B
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≤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个空格,最左边和最右边的数字确定,相邻的空格数字之差(绝对值)在[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的更多相关文章
- AtCoder Grand Contest 017 F - Zigzag
题目传送门:https://agc017.contest.atcoder.jp/tasks/agc017_f 题目大意: 找出\(m\)个长度为\(n\)的二进制数,定义两个二进制数的大小关系如下:若 ...
- AtCoder Grand Contest 017 (VP)
contest link Official Editorial 比赛体验--之前做题的时候感觉 AtCoder 挺快的,现在打了VP之后发现还是会挂的--而且不是加载缓慢或者载不出来,直接给你一个无法 ...
- AtCoder Grand Contest 017 题解
A - Biscuits 题目: 给出 \(n\) 个物品,每个物品有一个权值. 问有多少种选取方式使得物品权值之和 \(\bmod\space 2\) 为 \(p\). \(n \leq 50\) ...
- AtCoder Grand Contest 017 迟到记
晚上去操场上浪. 回来以后看到好几个人开着 \(AtCoder\) 在打代码. ... ... 今天有 \(AtCoder\) 比赛 ? 管它呢, \(Kito\) 在切西瓜,先吃西瓜... 然后看 ...
- AtCoder Grand Contest 017
noi前橙名计划失败.全程搞C而gg…… A - Biscuits 题意:背包,求价值为奇/偶的方案数. #include<cstdio> #include<queue> #i ...
- 题解——ATCoder AtCoder Grand Contest 017 B - Moderate Differences(数学,构造)
题面 B - Moderate Differences Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stat ...
- AtCoder Grand Contest 017 A
Problem Statement There are N bags of biscuits. The i-th bag contains Ai biscuits. Takaki will selec ...
- 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(& ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
随机推荐
- Vs2012在Linux开发中的应用(6):改写Makefile项目的Build过程
MSBUILD的编译过程实际上是依据一系列的targets文件定义的.当我们在IDE运行生成.批生成.清理命令的时候.VS会查找这些命令相应的Task并运行它,以下我们逐个分析这个过程. 当运行生成操 ...
- 提升vector性能的几个技巧
原文:https://www.sohu.com/a/120595688_465979 Vector 就像是 C++ STL 容器的瑞士军刀.Bjarne Stoutsoup 有一句话 – “一般情况下 ...
- cat /proc/cpuinfo | awk -F: '/name/{print $2}' | uniq -c
cat /proc/cpuinfo | awk -F: '/name/{print $2}' | uniq -c
- Delphi通过POST传递参数给PHP
Delphi代码 ******************************************************************************************* ...
- YTU 2429: C语言习题 学生成绩输入和输出
2429: C语言习题 学生成绩输入和输出 时间限制: 1 Sec 内存限制: 128 MB 提交: 1897 解决: 812 题目描述 编写一个函数print,打印一个学生的成绩数组,该数组中有 ...
- java.lang.IllegalArgumentException: No converter found for return value of type: class com.st.bean.User
原因:springmvc默认是没有对象转换成json的转换器的,要添加jackson依赖 在pom.xml中添加 <dependency> <groupId>com.faste ...
- hdu 1043 Eight(双向bfs)
题意:经典八数码问题 思路:双向bfs ps:还有a*算法(还不会)等解法. 代码: #include<iostream> #include<stdio.h> #include ...
- netty codec部分剖析
针对netty 3.2进行剖析 今天用到了netty的encoder和decoder(coder其本质还是handler),特剖析一个netty提供的coder,从而选择或者实现我自己的coder. ...
- RxJava RxBinding 按钮(Button) 点击(click)
/********************************************************************* * RxJava RxBinding 按钮(Button) ...
- SPOJ:Robot(数学期望)
There is a robot on the 2D plane. Robot initially standing on the position (0, 0). Robot can make a ...