题目链接:http://codeforces.com/problemset/problem/716/A

题目大意:

  输入 n c, 第二行 n 个整数,c表示时间间隔 秒。

  每个整数代表是第几秒。如果本次和下一秒间隔>c 则之前的计数次数清0,否则每次输入一个数,计数++;

  问最后剩几个数。

举例:

input:

6 5
1 3 8 14 19 20

output:

 3

解析:

1 3 8 此时剩 3 个数,因为每次输入距离下次输入时间间隔都<5。下一次是 14 距离上一次 间隔为14-8>5 ,计数清0。

下一次 19-14<5 保留,下一次 20-19<5 保留,故此时剩下 14 19 20 。所有输出 3.

解题思路:

  先输入一个数,然后for剩下的数,如果下一个数与前一个是查大于 c 则cut=0,否则cut++;最后输出 cut+1.为什么+1 读者自己思考,可参考举例解析。

AC Code:

 #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,c;
while(scanf("%d%d",&n,&c)!=EOF)
{
int i;
int x,x1,cut=;
scanf("%d",&x);
for(i=; i<n; i++)
{
scanf("%d",&x1);
if((x1-x)>c)
cut=;
else cut++;
x=x1;
}
printf("%d\n",cut+);
}
return ;
}

CodeForces 716A Crazy Computer的更多相关文章

  1. 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 i ...

  2. Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word

    Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...

  3. Crazy Computer

    ZS the Coder is coding on a crazy computer. If you don't type in a word for a cconsecutive seconds, ...

  4. Codeforces 498A Crazy Town

    C. Crazy Town time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. Codeforces 499C:Crazy Town(计算几何)

    题目链接 给出点A(x1,y1),B(x2,y2),和n条直线(ai,bi,ci,aix + biy + ci = 0),求A到B穿过多少条直线 枚举每条直线判断A.B是否在该直线两侧即可 #incl ...

  6. CF716A Crazy Computer 题解

    Content 有一个电脑,如果过了 \(c\) 秒之后还没有任何打字符的操作,就把屏幕上面所有的字符清空.现在,给定 \(n\) 次打字符的时间 \(t_1,t_2,...,t_n\),求最后屏幕剩 ...

  7. Codeforces水题集合[14/未完待续]

    Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...

  8. Codeforces Round #370 - #379 (Div. 2)

    题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi  ...

  9. 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 consecut ...

随机推荐

  1. 快速向表中插入大量数据Oracle中append与Nologging

    来源于:http://blog.sina.com.cn/s/blog_61cd89f60102e7gi.html 当需要对一个非常大的表INSERT的时候,会消耗非常多的资源,因为update表的时候 ...

  2. Kernel Methods (1) 从简单的例子开始

    一个简单的分类问题, 如图左半部分所示. 很明显, 我们需要一个决策边界为椭圆形的非线性分类器. 我们可以利用原来的特征构造新的特征: \((x_1, x_2) \to (x_1^2, \sqrt 2 ...

  3. jsoup-提示java.net.SocketTimeoutException:Read timed out

    使用Jsoup.connect(url).get()连接某网站时偶尔会出现 java.net.SocketTimeoutException:Read timed out异常. 原因是默认的Socket ...

  4. request 和response

    当今web程序的开发技术真是百家争鸣,ASP.NET, PHP, JSP,Perl, AJAX 等等. 无论Web技术在未来如何发展,理解Web程序之间通信的基本协议相当重要, 因为它让我们理解了We ...

  5. Yii2的Debug工具

    yii2的Debug工具 调用   r=debug 可以对程序进行性能分析,从而对程序进行改良 (1)数据库某条sql语句的执行时间 (2)debug的profiling标签 \YII::beginP ...

  6. printf 命令

    格式替代符 %b 相对应的参数被视为含有要被处理的转义序列之字符串. %c ASCII字符.显示相对应参数的第一个字符 %d, %i 十进制整数 %e, %E, %f 浮点格式 %g %e或%f转换, ...

  7. BIEE11G配置Oracle数据源

    注:数据库发生变化只需要修改视图层 两种方式: (1)       在BIEE自带的Oracle客户端目录下的tnsname.ora文件中配置 把E:\app\Administrator\produc ...

  8. 算法求和sum问题

    问题:SUM(n) = 1 + 2 + 3 + ... + n写个算法 回答: #include<stdio.h>int main(){    int n,sum;    while(sc ...

  9. 【BZOJ-1042】硬币购物 容斥原理 + 完全背包

    1042: [HAOI2008]硬币购物 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1811  Solved: 1057[Submit][Stat ...

  10. macOS 安装 wget

    适用于macOS Sierra Apple Store下载安装Xcode 安装Homebrew包管理,类似于Ubuntu下的apt-get: 终端下输入 ruby -e "$(curl -f ...