您的位置:首页 > 其它

CF Bear and Game

2016-05-28 12:04 274 查看
Bear and Game
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status
Description
BearLimak likes watching sports on TV. He is going to watch a game today. The gamelasts 90 minutes
and there are no breaks.
Eachminute can be either interesting or boring. If 15 consecutiveminutes are boring then
Limak immediately turns TV off.
Youknow that there will be n interestingminutes t1, t2, ..., tn.Your
task is to calculate for how many minutes Limak will watch the game.
描述
熊Limak喜欢看电视上的体育节目。他今天去看一场比赛。游戏持续90分钟,没有休息。
 
每分钟可以有趣或无聊。如果连续15分钟是无聊的,然后Limak立即把电视关掉。
 
你知道会有n个有趣的时间点,时间点分别是t1,t2,…,tn。你的任务是计算有多少分钟Limak将观看比赛。
 
输入
输入的第一行包含一个整数n(1≤n≤90)-有趣的分钟数。
 
第二行包含n个整数t1,t2,…tn(1≤t1< t2 <…tn≤90),增加的顺序。
 
输出
打印的数量分钟Limak将观看比赛。
Input
Thefirst line of the input contains one integer n (1 ≤ n ≤ 90) —the
number of interesting minutes.
Thesecond line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... tn ≤ 90),given
in the increasing order.
Output
Printthe number of minutes Limak will watch the game.
Sample Input
Input
3

7 20 88
Output
35
Input
9

16 20 30 40 50 60 70 80 90
Output
15
Input
9

15 20 30 40 50 60 70 80 90
Output

 90
 
 
 
题意:统计看电视的最多时间,如果无聊的时间间隔>15就不看电视,敲代码去。

 

代码如下:

 /*=============================AC情况===============================*/
/*题目网址: */
/*时间: */
/*心得: 看得懂英语,知道题目的题意很重要 */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define G 100

int main() {
int n,t[G],ans;
while(scanf("%d",&n)!=EOF) {
for(int j=1; j<=n; j++)
scanf("%d",&t[j]);
ans=15;
for (int j=1 ; j<=n; j++) {
if (t[j] <= ans)
ans = t[j] + 15;
else
break;
}
if(ans>90)
ans=90;
printf("%d\n",ans);
}
return 0;
}

/*********************************测试数据*********************************

**************************************************************************/


 错误代码(没找到bug):

 
 /*=============================AC情况===============================*/
/*题目网址: */
/*时间: */
/*心得: 看得懂英语,知道题目的题意很重要 */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define G 100

int main() {
int n,t[G],ans;
while(scanf("%d",&n)!=EOF) {
t[0]=0;//兴致勃勃的去看比赛
for(int j=1; j<n+1; j++)
scanf("%d",&t[j]);
/* if(t[1]>15) {
printf("15\n");
continue;
}*/
ans=0;
for(int j=0; j<n; j++) {
if(t[j+1]-t[j]<=15)//有趣的时间点持续更新中
ans=t[j+1];
else {
ans=ans+15;
break;
}
}
if(ans>90)
ans=90;
printf("%d\n",ans);
}
return 0;
}

/*********************************测试数据*********************************

**************************************************************************/

 
 
 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: