# Climbing Worm

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12570    Accepted Submission(s): 8491

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

水题一道 ， 说看注释吧

#include<iostream>
#include<cstdio>
using namespace std;

int main()
{
//题目大意 就是一共有N步 虫值每分钟走u 步 然后休息一分钟后d步
int n , d , u;
while(scanf("%d%d%d", &n, &u, &d), n)
{
int len = 0;//用来记录虫子走的路程
int sum = 0 ;//用来记录时间
while(len < n)
{
sum += 1;
len += u;
if(len >= n)
{//大于等于那么退出
break;  //跳出循环的条件
}
len -= d; //休息一分钟
sum += 1;
}
printf("%d\n", sum);
}

}


wangxiaoming CSDN认证博客专家 架构 Spring Boot Redis

04-19 214

11-09 312
02-14 1382
04-07 26
05-28 285
11-26 887
08-20 300
01-14 922
10-15 363
05-05 825
04-05 888
08-03 742
09-28
09-04
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。