zoukankan      html  css  js  c++  java
  • Codeforces Round #362 (Div. 2)->A. Pineapple Incident

    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 + 1, t + 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 ≤ 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.

    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 3, 13, 14, ..., so it won't bark at the moment 4and 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.

    思路:用sum表示barks的时间,如果x等于sum的话就输出yes,否则输出no,注意如果x==t的话也是可以的

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main()
     4 {
     5     int t,s,x;
     6     cin>>t>>s>>x;
     7     int sum=0;
     8     int i=1;
     9     int flag=1;
    10     if(t==x)
    11         flag=0;
    12     else
    13     {
    14         while(sum<x)
    15         {
    16             sum=t+i*s;
    17             if(sum==x)
    18             {
    19                 flag=0;
    20                 break;
    21             }
    22             sum=t+i*s+1;
    23             if(sum==x)
    24             {
    25                 flag=0;
    26                 break;
    27             }
    28             i++;
    29         }
    30     }
    31     if(flag)
    32         cout<<"NO"<<endl;
    33     else
    34         cout<<"YES"<<endl;
    35     return 0;
    36 }
  • 相关阅读:
    url传参数出现乱码解决方法
    ASP.NET 当GridView中没有数据的时候,显示标题栏 并且给出一行数据提
    纯手工打造 IFAN (光盘回收及午餐筷子回收事业)
    javascript 收集
    Winform 中的控件透明设置要点
    对指定的网页进行截图 C#版
    生成短GUID的两个方法
    按键相关的 JS脚本代码
    ISCSI Enterprise Target 的其他资源和地址
    ORA01403:no data found 解决方法两则
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/5673502.html
Copyright © 2011-2022 走看看