CodeForces 697A Pineapple Incident(数列,水下题)

    xiaoxiao2026-09-13  2

    http://codeforces.com/problemset/problem/697/A

    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 3 10 4 output NO input 3 10 3 output YES input 3 8 51 output YES input 3 8 52 output 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;过 s 秒后再叫(记得是两次);判断的时间点

    思路:

    给定的是两个等差数列,无奈的就是自己保证了 a2>0 但是没考虑 a1 的正负!

    Code:

    #include<stdio.h> #include<cstring> const int MYDD=1103; int main() { int t,s,x; while(scanf("%d%d%d",&t,&s,&x)!=EOF) { double a1,a2; // if(x==t+s) { // puts("YES"); // continue; // } // a1=(x-t)*1.0/(s*1.0); a2=(x-t-1)*1.0/(s*1.0); if((a1==(int)a1&&a1>=0)||(a2==(int)a2&&a2>0)) puts("YES");//会叫 miaomiao 的 else puts("NO"); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-1312016.html
    最新回复(0)