落絮飞雁

顺流而下,把梦做完

HDOJ1049:Climbing Worm——基础题

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

像是小学算术题。没什么好说的,一次过。
放上代码:

#include
int main()
{
	int n, u, d, route, t;
	while (scanf("%d%d%d", &n, &u, &d) && n)
	{
		t = 0;
		route = n;
		while (1)
		{
			route -= u;
			t++;
			if (route 

原文标题:HDOJ1049:Climbing Worm——基础题|落絮飞雁的个人网站
原文链接:https://www.luoxufeiyan.com/2015/03/13/hdoj1049/
授权协议:创作共用 署名-非商业性使用 2.5 中国大陆
除注明外,本站文章均为原创;转载时请保留上述链接。