「HD_ACM」Climbing Worm
2015-05-03 19:17
393 查看
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. ->一只虫子一不小心掉进一个n英寸深洞中。它有足够的能量来爬你每分钟英寸,但随后必须休息一分钟之前再次攀升。在休息期间,它滑落d英寸。攀爬的过程和休息然后重复。多久前的虫子爬出好吗?我们会永远数每分钟作为一个整体的一部分,如果虫子只是达到顶端的最后的攀爬,我们将假设蠕虫让出来。 |
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. ->将会有多个问题实例。每一行将包含三个正整数n,u和d。在上面的段落中提到这些给值。此外,你可以假设d < u和n < 100。n = 0表示值的输出。 |
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. ->每个输入实例应该生成一个整数,指示分钟的数量需要的虫子爬出来的。 |
虫子一分钟向上爬 , 一分钟休息并向下滑落 , 虫子在爬上来后 不下滑
代码分析
#include <stdio.h> #include <stdlib.h> int main() { int n,d,u; //n:洞深 、d:向上爬的长度 、u:下滑的长度 int t; //所需要的天数 int s=0; //实际爬行长度 while(scanf("%d %d %d" , &n ,&d ,&u) !=EOF && n !=0 && d != 0 && u != 0) { t=0; s=0; while(1) { s+=d; t++; if(s>=n) break; s-=u; t++; } printf("%d\n" , t); } return 0; }
相关文章推荐
- 「HD_ACM」A+B for Input-Output Practice (IV)
- HD ACM Wolf and Rabbit
- ACM水题 Climbing Worm
- 「HD_ACM」A+B for Input-Output Practice (V)
- 「HD_ACM」The Seven Percent Solution
- HD1049Climbing Worm
- 「HD_ACM」A+B for Input-Output Practice (VI)
- 【杭电ACM】1.2.2 Climbing Worm
- ACM--虫子爬井--模拟--HDOJ 1049--Climbing Worm--水
- 「HD_ACM」A+B for Input-Output Practice (VII)
- 「HD_ACM」IBM Minus One
- 「HD_ACM」A+B for Input-Output Practice (VIII)
- HD ACM 1061 Rightmost Digit
- HD ACM 2.1.6 整数对
- ACM题解报告——HD1006
- 「HD_ACM」 A+B for Input-Output Practice (I)
- 「HD_ACM」 A+B for Input-Output Practice (II)
- HD ACM C++ 1014
- 「HD_ACM」A+B for Input-Output Practice (III)
- ACM题解报告——HD1022