• Codeforces 716A Crazy Computer


    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6416004.html

    A. Crazy Computer

    time limit per test:2 seconds
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

      ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear!

      More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then everything on the screen disappears and after that the word you have typed appears on the screen.

      For example, if c = 5 and you typed words at seconds 1, 3, 8, 14, 19, 20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.

      You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.

    Input

      The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively.

      The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.

    Output

      Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.

    Examples
    Input
    6 5
    
    
    1 3 8 14 19 20
    Output
    3
    Input
    6 1
    
    
    1 3 5 7 9 10
    Output
    2
    Note

    The first sample is already explained in the problem statement.

    For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.

     解法:

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4     int n,t,a[100005];
     5     while(cin>>n>>t){
     6         for(int i=0;i<n;i++)cin>>a[i];
     7         int num=1;
     8         for(int i=0;i<n-1;i++){
     9             if(a[i+1]-a[i]<=t)num++;
    10             else num=1;
    11         }
    12         cout<<num<<endl;
    13     }
    14     return 0;
    15 } 
  • 相关阅读:
    “图”以致用组
    水体频率小组
    2021年云开发组三等奖作品展示
    毫秒级百万数据分页存储过程[欢迎转载]
    SQL Server 数据备份存储过程[原创]
    博客园居然被中国电信提醒有病毒,有图为证
    网络文件夹例子
    小技巧:在DropDownList数据绑定前插入固定文字
    ASP.NET整合Discuz!NT3.5实例说明(含用户登录、评论等)
    Visual Studio 2008的性能改进以及十大新功能(转)
  • 原文地址:https://www.cnblogs.com/cruelty_angel/p/10428994.html
Copyright © 2020-2023  润新知