Atcoder B - Moderate Differences
http://agc017.contest.atcoder.jp/tasks/agc017_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
依题可得:c<=x(i+1)-xi<=d 或者 -d<=x(i+1)-xi<=-c;
且有∑(xi+1-xi)=xN-xN-1+.....+x3-x2+x2-x1=xN-x1=b-a
如果有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 <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
ll a,n,b,c,d;
while(cin>>n>>a>>b>>c>>d)
{
ll k=;
for(ll i=;i<n;i++)
{
if((c*(n-i-)-i*d)<=(b-a)&&(b-a)<=(d*(n-i-)-i*c))
{
puts("YES");
goto eg;
}
}
puts("NO");
eg:;
}
return ;
}
Atcoder B - Moderate Differences的更多相关文章
- 题解——ATCoder AtCoder Grand Contest 017 B - Moderate Differences(数学,构造)
		
题面 B - Moderate Differences Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stat ...
 - Atcoder | AT2665 【Moderate Differences】
		
又是一道思路特别清奇的题qwq...(瞪了一上午才发现O(1)的结论...差点还想用O(n)解决) 问题可以转化为是否能够由\(f_{1}=a\)通过\(\pm x \in[c,d]\)得到\(f_{ ...
 - Atcoder #017 agc017 B.Moderate Differences 思维
		
LINK 题意:给出最左和最右两个数,要求往中间填n-2个数,使得相邻数间差的绝对值$∈[L,R]$ 思路:其实也是个水题,比赛中大脑宕机似的居然想要模拟构造一个数列,其实我们只要考虑作为结果的数,其 ...
 - AtCoder Grand Contest 017 题解
		
A - Biscuits 题目: 给出 \(n\) 个物品,每个物品有一个权值. 问有多少种选取方式使得物品权值之和 \(\bmod\space 2\) 为 \(p\). \(n \leq 50\) ...
 - AtCoder Grand Contest 017 (VP)
		
contest link Official Editorial 比赛体验--之前做题的时候感觉 AtCoder 挺快的,现在打了VP之后发现还是会挂的--而且不是加载缓慢或者载不出来,直接给你一个无法 ...
 - AtCoder Grand Contest 017
		
noi前橙名计划失败.全程搞C而gg…… A - Biscuits 题意:背包,求价值为奇/偶的方案数. #include<cstdio> #include<queue> #i ...
 - 【AtCoder】AGC017
		
在此处输入标题 标签(空格分隔): 未分类 A - Biscuits dp[i][0/1]表示当前和是偶数还是奇数,直接转移即可 #include <bits/stdc++.h> #def ...
 - AtCoder Grand Contest 017 B
		
B - Moderate Differences Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Stateme ...
 - Noip2017赛前的一些记录
		
前言 已经退役整整五个月了....选考以后终于又摸上了键盘.... 但是码力已经大不如前了........ 距离比赛也就只有一星期了....那就胡乱的做一些题目吧QAQ 这里是一些根据算法分类的咋杂题 ...
 
随机推荐
- Kneser猜想与相关推广
			
本文本来是想放在Borsuk-Ulam定理的应用这篇文章当中.但是这个文章实在是太长,导致有喧宾夺主之嫌,从而独立出为一篇文章,仅供参考.$\newcommand{\di}{\mathrm{dist} ...
 - Swift编写的一些完整的app
			
收集了一些实用swift编写的app,这些demo都是不错的值得学习的. 知乎日报 Swift-ZhihuDaily Swift版知乎日报 参照了YANGReal的糗事百科和uitableview的例 ...
 - bzoj1050【HAOI2006】旅行comf
			
1050: [HAOI2006]旅行comf Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2205 Solved: 1174 [Submit][ ...
 - JS 去除字符串中的最后一个字符
			
var str = 'Hello World!'; str = str.substr(0,str.length-1); alert(str);
 - Linux在中国的没落
			
6月23日,Linux kernel 4.1(LTS)公布.在国际自由软件世界引起热烈反响. 反观我们国内,官方机构没有不论什么动静:在民间,Linux激情已经消失.与十几年前相比.Linux在国内已 ...
 - android 自己定义dialog并实现失去焦点(背景透明)的功能
			
前言:因为在项目中须要用到更新显示动画的需求,所以想到了dialog,自己定义dialog不难.网上教程非常多,可是在实现dialog背景透明的需求时,遇到了一点问题.网上的一些方法在我的机器上并没有 ...
 - 卸载虚拟机时错误关闭了某个服务,使得电脑除了chrome浏览器都不能联网
			
不是中毒,也不需要重装系统,可能是关闭了svchost服务 以下为搜索到的答案,亲测第一种好用 最近两周在三班四班有5位同学电脑7次出现网络故障,表现为能连上锐捷.DNS正常却不能上网,其中在我自己的 ...
 - Mysql锁表
			
lock tables是线程锁定表 lock tables table_name read lock tables table_name write read表示 所有用户只能读取被锁的表,不能对其进 ...
 - Android带弹性的View
			
在Android开发中ListView.ScrollView用到的频率相当高,可是一个优秀的应用我们能看到它里面的效果绝对不会那么死板,安卓原生的ListView和ScrollView都不能满足这个要 ...
 - js实现观察者模式风格替换
			
如下图,我们看到两种风格:在选择男士时,页面颜色为黑色:在选择女士时,页面颜色为粉红色. 主要可以分为两类: 下拉框 ---> 被观察者 div ---> 观察者 面向过程实现风格替换: ...