【Codeforces Round #372 (Div. 2)】Codeforces 716A Crazy Computer

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.

模拟。倒序循环即可。

#include<cstdio>
#include<cstring>
int a[100010];
int main()
{
    int i,j,k,m,n,x,y,z,p,q,c;
    scanf("%d%d",&n,&c);
    for (i=1;i<=n;i++)
      scanf("%d",&a[i]);
    for (i=n-1;i;i--)
      if (a[i+1]-a[i]>c)
        break;
    printf("%d\n",n-i);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值