codeforces 697A Pineapple Incident

本文探讨了一个趣味算法问题:一个特殊能吠叫的‘松果’遵循特定的时间间隔进行吠叫。根据首次吠叫时间、吠叫间隔及巴尼打算吃掉松果的时间,判断该时刻松果是否会吠叫。通过分析给出的样例输入输出,可以快速掌握问题解决技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击打开链接

A. Pineapple Incident
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 tt + st + s + 1t + 2st + 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.

Input

The first and only line of input contains three integers ts and x (0 ≤ t, x ≤ 1092 ≤ 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.

Output

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.

Examples
input
Copy
3 10 4
output
Copy
NO
input
Copy
3 10 3
output
Copy
YES
input
Copy
3 8 51
output
Copy
YES
input
Copy
3 8 52
output
Copy
YES
Note

In the first and the second sample cases pineapple will bark at moments 31314, ..., 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 311121920272835364344515259, ..., so it will bark at both moments 51 and 52.


水题,注意t,t+s,t+s+1,这三个要单独判断,后边的就是规律了

#include<bits/stdc++.h>  
using namespace std;  
typedef long long ll;  
const int inf = 0x3f3f3f3f;  
int main()   
{  
    // freopen("shuju.txt","r",stdin);
    int t,s,x;
    cin>>t>>s>>x;
    int flag=1;
    if(x==t||x==t+s||x==t+s+1)
    {
        printf("YES\n");
        flag=0;
    }
    else if(x<t+s+1)
    {
        printf("NO\n");
        flag=0;
    }
    if(flag)
    {
        if((x-t)%s==0||(x-1-t)%s==0)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;  
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值