Codeforces 697A - Pineapple Incident
来源:互联网 发布:shake it of 编辑:程序博客网 时间:2024/06/15 18:57
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1, etc.
Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time x (in seconds), so he asked you to tell him if it's gonna bark at that time.
The first and only line of input contains three integers t, s and x (0 ≤ t, x ≤ 109, 2 ≤ s ≤ 109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
Print a single "YES" (without quotes) if the pineapple will bark at time x or a single "NO" (without quotes) otherwise in the only line of output.
3 10 4
NO
3 10 3
YES
3 8 51
YES
3 8 52
YES
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52.
通过写出条件可以得知,所要求的Xn一定属于以下区间的时候是YES
t<=x1<=t+s<=x2<=t+s+1<=x3<=t+2s....
可以得出
0<=x-t-n*s<=s 即当(x-t)%s==0时或0<=x-t<=1是在bark time的
还有一种情况是x<t时是一定不在的,注意特判一下就好。
#include<stdio.h>#include<iostream>using namespace std;int main(){ int t,x,s; cin>>t>>s>>x; if (((x-t)%s==0&&x-t>=0)||x>=t&&(x-t-1)%s==0&&(x-t-1)!=0) { printf("YES"); }else { printf("NO"); }}
- Codeforces 697A - Pineapple Incident
- CodeForces 697A Pineapple Incident
- Codeforces 697A. Pineapple Incident (模拟)
- CodeForces 697 A. Pineapple Incident(水~)
- CodeForces 697A Pineapple Incident(数列,水下题)
- cdeforces 697 A. Pineapple Incident (数学)
- A. Pineapple Incident
- codeforces #362(div.2)A.Pineapple Incident【水题】
- Codeforces Round #362 (Div. 2) A. Pineapple Incident
- 【Codeforces Round 362 (Div 2)A】【简单讨论】Pineapple Incident
- Codeforces Round #362 (Div. 2) A. Pineapple Incident
- Codeforces Round #362 (Div. 2) A. Pineapple Incident(水题)
- Pineapple Incident
- Pineapple Incident,Barnicle,Lorenzo Von Matterhorn(cf#362)
- CodeForces-a
- Codeforces 903A A
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- 2JSP内置对象
- computer vision一些术语-目标识别、目标检测、目标分割、语义分割等
- 等间距布局 - 从0开始说一下masonry的使用
- 2016.07.14【初中部 NOIP提高组 】模拟赛C题目
- 多态,就是重载和重写/覆盖
- Codeforces 697A - Pineapple Incident
- 160715_发现md文档是一个很有趣的新奇玩意儿!
- 3JSP与Javabean
- 生成随机验证码
- 【旧代码整理】做的一个简单的php mvc框架
- Java解析XML文件的四种方法
- unity3d 压缩文件夹和压缩文件
- android listview 异步加载图片并防止错位
- Sum of Two Integers