Climbing Worm
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 23456 Accepted Submission(s): 16050
Problem De ion
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
题目理解
普通的蜗牛爬井题,注意不要加上最后一次下滑的时间就ok。
#include<iostream>
using namespace std;
int main()
{
int n, u, d, t = 0,s = 0 ;//time&S
while (cin >> n >> u >> d)
{
if (n == 0 )break;
while (1)
{
s += u;
t++;
if (s >= n)
{
cout << t;
break;
}
s -= d;
t++;
}
t = 0;
s = 0;
cout << endl;
}
}
继续阅读与本文标签相同的文章
vue数据双向绑定
-
在如今,人们谈到科技,可能最先想到的就是电子技术
2026-05-18栏目: 教程
-
特斯拉Model Y“将于2020年第一季度”开始生产
2026-05-18栏目: 教程
-
重科技、重创新、重人才 常德高新区连续两年举办高新技术交流会
2026-05-18栏目: 教程
-
iRobot擦地机器人上新,更有意义的是机器人间互动的实现
2026-05-18栏目: 教程
-
科技的不断进步,分享缤越智能领航系统的使用方法
2026-05-18栏目: 教程
