zoukankan      html  css  js  c++  java
  • Codeforces-716A-Crazy Computer

    Time limit
    2000 ms
    Memory limit
    262144 kB

    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.
    

    Example
    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.
    

    代码:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;  
    
    int data[100005];
    
    int main()  
    {  
        int N,C;
        cin>>N>>C;
        for(int i=0 ; i<N ; i++)scanf("%d",&data[i]);
        int sum = 1;
        int flag = data[0];
        for(int i=1 ; i<N ; i++)
        {
            if(data[i]-flag>C)sum = 0;
            flag = data[i];
            sum++;
        }
        cout<<sum<<endl;
        return 0;   
    }   
  • 相关阅读:
    hdu 5400 Arithmetic Sequence(模拟)
    hdu 5402 Travelling Salesman Problem(大模拟)
    hdu 5009 Paint Pearls (dp)
    poj 1236 Network of Schools(tarjan+缩点)
    hdu 3836 Equivalent Sets(tarjan+缩点)
    编程之美2015初赛第一场 hihoCoder #1156 : 彩色的树(染色问题)
    hdu 2807 The Shortest Path(矩阵+floyd)
    The Unique MST (判断是否存在多个最小生成树)
    Advanced Fruits(好题,LCS的模拟)
    Dark roads(kruskal)
  • 原文地址:https://www.cnblogs.com/vocaloid01/p/9514223.html
Copyright © 2011-2022 走看看