Climbing Worm

Climbing Worm
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24948 Accepted Submission(s): 17042

Problem Description
An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and resting then repeats. How long before the worm climbs out of the well? We’ll always count a portion of a minute as a whole minute and if the worm just reaches the top of the well at the end of its climbing, we’ll assume the worm makes it out.

Input
There will be multiple problem instances. Each line will contain 3 positive integers n, u and d. These give the values mentioned in the paragraph above. Furthermore, you may assume d < u and n < 100. A value of n = 0 indicates end of output.

Output
Each input instance should generate a single integer on a line, indicating the number of minutes it takes for the worm to climb out of the well.

Sample Input
10 2 1
20 3 1
0 0 0

Sample Output
17
19

Source
East Central North America 2002

Recommend
We have carefully selected several similar problems for you: 1021 1019 1005 1108 1071

题目大意:有一口井深n米,有一只蜗牛可以保持v(m/s)的速度匀速上爬一秒,爬一秒后不得不休息一秒,在休息的这一秒期间,它又下滑d米;
算蜗牛到达井口所需的时间(不到一秒按一秒算);
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n,v,d;
	while (cin >> n&&n!=0)
	{
		cin >> v >> d;
		int total= 0;
		int k = 0, time = 0;
		while (total < n)
		{
			if (k)
			{
				total -= d;
				time++;
			}
			k = 1;
			total += v;
			time++;
		}
		cout << time << endl;
	}
	system("pause");
	return 0;
}
全部评论

相关推荐

嵌入式小辣鸡:包装好一点,校内的奖项可以不用写,校内项目经历最后两点写的太差了,详细讲一下内容,名字变一下。只需要写项目实现了什么,自己在其中做了什么就好,查看图片
点赞 评论 收藏
分享
喜欢疯狂星期四的猫头鹰在研究求职打法:短作业优先
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务