codeforces—— 716A —— Crazy Computer
来源:互联网 发布:客户数据库表格 编辑:程序博客网 时间:2024/06/01 23:55
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.
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.
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.
6 51 3 8 14 19 20
3
6 11 3 5 7 9 10
2
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.
输入n,m,一共输入n个数,每输入一个数,如果与前一个差值大于m,则只保留刚输入的数。问输入结束,剩余几个数。
水题。不幸WA两次,也是醉了
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<stack>#include<algorithm>using namespace std;int main(){ int n,m; while(cin>>n>>m) { stack<int>sta1; while(n--) { int temp; cin>>temp; sta1.push(temp); } int ans=0; while(sta1.size()>1) { int temp=sta1.top(); sta1.pop(); ans++; if(temp-sta1.top()>m) if(sta1.size()==1) ans--; else break; } if(sta1.size()==1) ans++; cout<<ans<<endl; } return 0;}
- codeforces—— 716A —— Crazy Computer
- Codeforces-716A-Crazy Computer
- Codeforces-716A-Crazy Computer
- Codeforces 716A A. Crazy Computer
- 【CodeForces】716A - Crazy Computer(水)
- 【Codeforces Round #372 (Div. 2)】Codeforces 716A Crazy Computer
- CodeForces 716A. Crazy Computer(简单实现,水)
- CodeForces-716A. Crazy Computer(太水)
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
- 【67.23%】【CF 716A】Crazy Computer
- A. Crazy Computer
- A. Crazy Computer
- Codeforces Round #372 (Div. 2)A. Crazy Computer
- Codeforces Round #372 (Div. 2) A.Crazy Computer/B. Complete the Word
- Codeforces Round #372 (Div. 2) A. Crazy Computer(显示字符)
- codeforces 498A crazy town
- codeforces 498 A Crazy Town
- Code Jam 2009 Round2 Problem A. Crazy Rows —— 贪心
- 字符串存入数据库date类型字段
- [RK3288][Android6.0] 一律运行WLAN漫游扫描选项
- javac编译 编码GBK的不可映射字符
- ActiveMQ—安装配置及使用
- laravel框架总结 -- composer基本使用
- codeforces—— 716A —— Crazy Computer
- Eclipse启动时提示An error has occurred.See the log file D:\eclipse\configuration\...
- angularjs基础用法
- unity3d VR的多个Canvas下UI交互射线穿透问题
- Intellij Idea 编译报错 javacTask: 源发行版 1.6 需要目标发行版 1.6
- android 点击图标,应用重新启动
- 串口CPU卡读写模块,串口银行卡读写模块,串口HCE读写模块
- RRDTOOL 学习
- 三层架构