【问题描述】
一条虫子在n英寸深的井底,每次一分钟爬行u英寸,但是它在再次爬行前必须先休息1分钟, 在休息过程中它将滑落d英寸,在反复向上爬行和休息后,多长时间虫子能爬出这口井?在此过程中,分钟的小数部分向上取整,如果攀爬结束时虫子正好到达井的顶部,则视为虫子已经爬出。假定d<u,n<100,当n=0时输入结束。
【输入形式】
输入包括多个测试用例。每行包含3个正整数n、u、d,为上面所提到的值。
【输出形式】
每个测试用例输入一行,表示虫子爬出井的时间。
【样例输入】
10 2 1 20 3 1 0 0 0
【样例输出】
17 19
#include <iostream>
using namespace std;
int main(){
while(true){
int n,u,d;
cin>>n>>u>>d;
if (n==0)break;
int time=0,height=0;
while(true){
time++;
height+=u;
if(height>=n){
break;
}
time++;
height-=d;
if(height<=0) break;
}
cout<<time<<endl;
}
}