zoukankan      html  css  js  c++  java
  • Codeforces Round #372 (Div. 2) A

    Description

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

    题意:相邻两个数如果差距大于K,就会把屏幕上的字符消去,反之就保留下来

    解法:一般输入就开始判断,如果大于就是初始化为1,否则就累计

    #include<stdio.h>
    //#include<bits/stdc++.h>
    #include<string.h>
    #include<iostream>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<queue>
    #include<map>
    #include<vector>
    #include<algorithm>
    #include<limits.h>
    #define MAXN (100000+10)
    #define MAXM (100000)
    #define inf 0x3fffffff
    #define INF 0x3f3f3f3f
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define ULL unsigned long long
    using namespace std;
    int a[100001];
    int c;
    int main()
    {
        int n;
        int cot=1;
        cin>>n>>c;
        cin>>a[0];
        for(int i=1;i<n;i++)
        {
            cin>>a[i];
            if(a[i]-a[i-1]<=c)
            {
                cot++;
            }
            else
            {
                cot=1;
            }
           // cout<<cot<<"A"<<endl;
        }
        cout<<cot<<endl;
        return 0;
    }
    

      

  • 相关阅读:
    实现用户密码登录
    面对不同类型老板,你该怎么办?
    11 款最好 CSS 框架 让你的网站独领风骚
    C#程序开发中经常遇到的10条实用的代码
    linux之Unable to find the ncurses libraries or the required header files.错误解决办法
    55+手绘网站设计 – 构建极具创新效果的网站
    超棒的JS移动设备滑动内容幻灯实现
    15个非常棒的jQuery无限滚动插件【瀑布流效果】
    前端性能优化:DocumentFragments或innerHTML取代复杂的元素注入
    TopFreeTheme精选免费模板【20130619】
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5880236.html
Copyright © 2011-2022 走看看