您的位置:首页 > 移动开发

Codeforces 697A. Pineapple Incident (模拟)

2016-07-16 16:21 351 查看
题目链接

简单题意

狗会在t时刻叫一声,之后每过s时间,他会叫两声,即在t+k*s和t+k*s+1时刻叫,给出一个时刻x,问狗会不会在x时刻叫

思路

当(x-t)%s ==0 或==1时叫,第一次特判,其他时间都不叫。

代码

#include <bits/stdc++.h>
using namespace std;
int main (){
int t,s,x;
cin >> t >> s >>x;
if(x == t){puts("YES"); return 0;}
if(x < s+t && x != t){puts("NO"); return 0;}
x -= t;
if(x < 0) {puts("NO");return 0;}
x %= s;
if(x ==0 || x == 1) puts("YES");
else puts("NO");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: