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. WEBGIS控制图层的显示

    看别人搞的GIS应用,常常有勾选.取消某个图层的操作,然后地图上就有相应的图形显隐,觉得好酷. 咋实现的? 其实说起来好像也不是特别复杂.在WEB端,实现该功能的原理和步骤是: 1.WEB端加载地图服 ...

  2. [git] csdn之code平台的使用

    简单的说一下GIT的使用.... 代码和托管平台是csdn刚出来没多久的code.csdn.net [中文的界面什么的简单点,好理解,嗯,易用....] Git 使用最新版:Git-1.8.4-pre ...

  3. 使用a标签下载文件,而不是直接打开,使用属性 download

    有的时候,下载的链接文件如果是普通文件类型,如txt,我们下载文件的时候,有的浏览器不会弹出下载框,.而是直接打开了该文件. 针对这种情况,我们只需要在a标签上加上download属性即可显示下载框. ...

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

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

  5. 简单的JDBC封装

    JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口 ...

  6. Watir: Watir-WebDriver对打开的浏览器attach操作

    Watir-WebDriver对于已经打开的浏览器,没有办法进行Attach操作. 但是对于自动化操作浏览器过程中点击某链接,打开的新浏览器,是能够定位到的. require 'watir-webdr ...

  7. python 使用multiprocessing需要注意的问题

    我们在编写程序的时候经常喜欢这样写代码 import MySQLdb import time from multiprocessing import Process conn = MySQLdb.co ...

  8. 聊聊Java SPI机制

    一.Java SPI机制 SPI(Service Provider Interface)是JDK内置的服务发现机制,用在不同模块间通过接口调用服务,避免对具体服务服务接口具体实现类的耦合.比如JDBC ...

  9. javascript ==等于与===恒等于

    ==判断是否等于,只判断数值 ===代表恒等于,不仅判断数值,而且判断类型 var a=5; var b="5"; (a b 只是数值上相等,但是类型并不相等) a==b //tr ...

  10. iphone 在设置了initial-scale=1 之后,在设置滚动条之后,没有滑动效果的解决办法

    iphone在设置了initial-scale=1 之后,我们终于可以以1:1 的比例进行页面设计了. 关于viewport,还有一个很重要的概念是:iphone 的safari 浏览器完全没有滚动条 ...