CodeForces 716A Crazy Computer
题目链接: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的更多相关文章
- 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 ...
- Codeforces Round #372 (Div. 2) A .Crazy Computer/B. Complete the Word
Codeforces Round #372 (Div. 2) 不知不觉自己怎么变的这么水了,几百年前做A.B的水平,现在依旧停留在A.B水平.甚至B题还不会做.难道是带着一种功利性的态度患得患失?总共 ...
- Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a cconsecutive seconds, ...
- Codeforces 498A Crazy Town
C. Crazy Town time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces 499C:Crazy Town(计算几何)
题目链接 给出点A(x1,y1),B(x2,y2),和n条直线(ai,bi,ci,aix + biy + ci = 0),求A到B穿过多少条直线 枚举每条直线判断A.B是否在该直线两侧即可 #incl ...
- CF716A Crazy Computer 题解
Content 有一个电脑,如果过了 \(c\) 秒之后还没有任何打字符的操作,就把屏幕上面所有的字符清空.现在,给定 \(n\) 次打字符的时间 \(t_1,t_2,...,t_n\),求最后屏幕剩 ...
- Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...
- Codeforces Round #370 - #379 (Div. 2)
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi ...
- 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 ...
随机推荐
- cocoaPods 的安装和使用
参考:http://www.360doc.com/content/14/0309/10/11029609_358970353.shtml
- java基础语法要点<二>(基于1.8)
注解(元数据) 从jdk5 开始,java支持在源文件中嵌入补充信息,称为注释(annotation).注释不会改变程序的动作,也就不会改变程序的语义.但在开发和部署期间,各种工具可以使用这类信息.元 ...
- jquery-jsrender使用
JsRender是一款基于jQuery的JavaScript模版引擎 特点: · 简单直观 · 功能强大 · 可扩展的 · 快如闪电 jsrender使用比较简单,本文简单结束一些常用的 使用过程 ...
- 小tip:纯CSS让overflow:auto页面滚动条出现时不跳动
本文转载于张鑫旭博客,原文地址:http://www.zhangxinxu.com/wordpress/?p=4552 一.水平居中布局与滚动条跳动的千年难题 当前web届,绝大多数的页面间布局都是水 ...
- 【USACO 2.1】Sorting A Three-Valued Sequence
/* TASK: sort3 LANG: C++ URL: http://train.usaco.org/usacoprob2?a=RkPIMxsFWzm&S=sort3 SOLVE: n个数 ...
- Cocoa pod的使用注意点
一.CocoaPods是什么? CocoaPods是一个负责管理iOS项目中第三方开源库的工具.CocoaPods的项目源码在Github上管理.该项目开始于2011年8月12日,在这两年多的时间里, ...
- Pycharm设置
File->settings->Editor->File and Code Templates->Python Script #!/usr/bin/env python # e ...
- Leetcode 306. Additive Number
Additive number is a string whose digits can form additive sequence. A valid additive sequence shoul ...
- Leetcode H-index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- MapReduce实现数据去重
一.原理分析 Mapreduce的处理过程,由于Mapreduce会在Map~reduce中,将重复的Key合并在一起,所以Mapreduce很容易就去除重复的行.Map无须做任何处理,设置Map中写 ...