您的位置:首页 > 其它

Problem A: Worm!!! -- 信息杯班级对抗赛

2014-12-13 12:59 148 查看

Problem A: Worm!!!

Time Limit: 1 Sec Memory Limit: 64 MB

Submit: 165 Solved: 81

[Submit][Status][Web
Board]

Description

一个虫子在n单位长度的井下面,每分钟他可以走u单位长度,但是之后他要休息一分钟,并且在休息的时候他会下滑d单位长度,那么请你计算一下它需要多长时间爬出井?

Input

输入包括n,u,d,并且d < u , n < 100.当n为0的时候输入结束

Output

输出一个数代表虫子爬出井需要的时间。

Sample Input

10 2 1
20 3 1
0 0 0

Sample Output

1719

HINT

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
int main()
{
int n,u,d;
int k = 0;
while(scanf("%d%d%d",&n,&u,&d) != EOF)
{
k = 0;
if(n == 0 &&u == 0 && d == 0)
return 0;

while(n > 0)
{
n = n - u;
k++;
if(n <= 0)       //当已经爬出来时,就不会再掉下去了
break;
n = n+d;
k++;
}
printf("%d\n",k);
}
return 0;
}

/**************************************************************
Problem: 1340
User: team47
Language: C
Result: Accepted
Time:0 ms
Memory:748 kb
****************************************************************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: