Codeforces 697A. Pineapple Incident (模拟)

来源:互联网 发布:数据编程是什么工作了 编辑:程序博客网 时间:2024/06/01 10:24

题目链接

简单题意

狗会在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;}
0 0
原创粉丝点击