zoukankan      html  css  js  c++  java
  • Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))

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

    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.

    题目链接:

      http://codeforces.com/contest/716/problem/A

    题目大意:

      给你一个N(N<=100000)个字母敲击的时间a[i](a[i]<=109),如果在M时间内没有敲击那么屏幕就清零,否则屏幕上就多一个字母,问最后屏幕剩下几个字母。

    题目思路:

      【模拟】

      从后往前做,只要找到第一个间隔超过M的就停止,统计当前的字母数量即可。

     1 //
     2 //by coolxxx
     3 //#include<bits/stdc++.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<map>
     9 #include<stack>
    10 #include<queue>
    11 #include<set>
    12 #include<bitset>
    13 #include<memory.h>
    14 #include<time.h>
    15 #include<stdio.h>
    16 #include<stdlib.h>
    17 #include<string.h>
    18 //#include<stdbool.h>
    19 #include<math.h>
    20 #define min(a,b) ((a)<(b)?(a):(b))
    21 #define max(a,b) ((a)>(b)?(a):(b))
    22 #define abs(a) ((a)>0?(a):(-(a)))
    23 #define lowbit(a) (a&(-a))
    24 #define sqr(a) ((a)*(a))
    25 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    26 #define mem(a,b) memset(a,b,sizeof(a))
    27 #define eps (1e-10)
    28 #define J 10000
    29 #define mod 1000000007
    30 #define MAX 0x7f7f7f7f
    31 #define PI 3.14159265358979323
    32 #pragma comment(linker,"/STACK:1024000000,1024000000")
    33 #define N 100004
    34 using namespace std;
    35 typedef long long LL;
    36 double anss;
    37 LL aans;
    38 int cas,cass;
    39 int n,m,lll,ans;
    40 int a[N];
    41 int main()
    42 {
    43     #ifndef ONLINE_JUDGEW
    44 //    freopen("1.txt","r",stdin);
    45 //    freopen("2.txt","w",stdout);
    46     #endif
    47     int i,j,k;
    48     int x,y,z;
    49 //    init();
    50 //    for(scanf("%d",&cass);cass;cass--)
    51 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    52 //    while(~scanf("%s",s))
    53     while(~scanf("%d",&n))
    54     {
    55         ans=1;
    56         scanf("%d",&m);
    57         for(i=1;i<=n;i++)
    58             scanf("%d",&a[i]);
    59         for(i=n;i>1;i--)
    60         {
    61             if(a[i]-a[i-1]>m)break;
    62             ans++;
    63         }
    64         printf("%d
    ",ans);
    65     }
    66     return 0;
    67 }
    68 /*
    69 //
    70 
    71 //
    72 */
    View Code
  • 相关阅读:
    python出现local variable 'f' referenced before assiginment""
    使用Python修改ifcfg-eth0文件
    在linux中运行py文件时,及时知道错误信息
    分词结果准确率、召回率计算-python
    oozie工作流
    combiner hadoop
    Python常用模块--base64
    Python常用模块--datetime
    树莓派(Raspbian系统)中使用pyinstaller封装Python代码为可执行程序
    LeetCode刷题笔记--Python--28. 实现strStr()
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5880147.html
Copyright © 2011-2022 走看看