Climbing Worm————攀缘蠕虫

    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

翻译一下就是

  一英吋的蠕虫是在一个N英吋深的井的底部。它有足够的能量每分钟攀登U英寸,但在再次攀登之前必须休息一分钟。在剩下的时间里,它滑下D英寸。攀登和休息的过程然后重复。虫子要多久才能从井里爬出来?我们总是把一分钟的时间作为一分钟的时间来计算,如果蠕虫在攀登的最后才到达井顶,我们就会假设蠕虫能把它弄出来。

输入

会有很多问题。每一行将包含3个正整数N、U和D。它们给出了上段中提到的数值。此外,你可以假设D

输出

每个输入实例都应该在一行上生成单个整数,表示蠕虫爬出井口所需的分钟数。

样本输入

10 2 1
20 3 1
0 0 0

样本输出

17
19

代码

include
int main()
{
    int n,u,d;
    while(scanf("%d%d%d",&n,&u,&d),n)
    {//将一上一下看成整个过程 
        int t=(n-u)/(u-d);
        if(t*(u-d)<(n-u)) t++;//不是一个整的过程,最后一次是上升的 
        t*=2;
        t++;
        printf("%d\n",t);
    }    
    return 0;
}

 

你可能感兴趣的:(C语言,hdoj)