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 这里是一些根据算法分类的咋杂题 ...
随机推荐
- 【codeforces 429D】Tricky Function
[题目链接]:http://codeforces.com/problemset/problem/429/D [题意] 给你n个数字; 让你求出一段区间[l,r] 使得 (r−l)2+(∑rl+1a[i ...
- otto源代码分析
otto这个开源项目是一个event bus模式的消息框架.用于程序各个模块之间的通信.此消息框架能够使得各个 模块之间降低耦合性. 此项目是支付公司square一个开源项目,项目托管于github ...
- [GDKOI2010] 圈地计划(网络流)
题2链接:https://www.luogu.org/problemnew/show/P1935 Description 最近房地产商GDOI(Group of Dumbbells Or Idiots ...
- PostgreSQL Replication之第三章 理解即时恢复(4)
3.4 重放事务日志 一旦我们创建了一个我们自己的初始基础备份,我们可以收集数据库创建的XLOG.当时间到时,我们可以使用所有这些XLOG 文件并执行我们所期望的恢复进程.这就像本节描述的一样工作. ...
- CMake入门之创建一个基于PCL的最小工程
最近在学习PCL,借助Cmake可省去繁琐的添加包含目录和依赖库操作. 一个典型的CMakeLists.txt内容通常为: cmake_minimum_required(VERSION 2.6 FAT ...
- Redis缓存Mysql模拟用户登录Java实现实例
https://blog.csdn.net/suneclipse/article/details/50920396
- 编译报错一列----aclocal找不到
编译源码包报错: 说aclocal这个命令找不到 解决: 使用 yum install -y automake问题解决
- LINUX 上源代码安装与配置samba服务,支持从windows上读写LINUX文件。
###动机###在windows编写代码文件比较方便,因为有source insight.但是需要在LINUX上编译.一种办法就是使用samba文件共享. [1] 下载samba代码.按照config ...
- caffe(11) 图像数据转换成db文件
在深度学习的实际应用中,我们经常用到的原始数据是图片文件,如jpg,jpeg,png,tif等格式的,而且有可能图片的大小还不一致.而在caffe中经常使用的数据类型是lmdb或leveldb,因此就 ...
- 学习Go语言之简易ORM框架
ORM即为对象关系映射,ORM常用于程序适配多种数据库,以达到开放扩展关闭修改的原则.笔者初学Golang,遂有意写个简易ORM框架,权当知识巩固. 首先需要有一个思想就是数据库表结构都是固定,但是每 ...