一些项目——An inch worm

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

代码

#include<iostream>
using namespace std;
int main()
{
    int n,d,u,t1=0,t2=0,count;
    while(cin>>n>>d>>u&&n!=0)
    {
        t1=0;
        t2=0;
        count=0;
        while(count<=n)
        {
            count+=d;
            t1++;
            if(count>=n)break;
            count-=u;
            t2++;
        }
        cout<<t1+t2<<endl;
    }
    return 0;
}
时间: 2024-10-07 05:15:53

一些项目——An inch worm的相关文章

hdu 1049 Climbing Worm

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

HDU 1049.Climbing Worm【水!水!水!】【8月25】

Climbing Worm 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

HDOJ 1049 Climbing Worm

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12116    Accepted Submission(s): 8149 Problem Description An inch worm is at the bottom of a well n inches deep. It has enough ener

Climbing Worm

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

NYOJ 1049 Climbing Worm

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12116    Accepted Submission(s): 8149 Problem Description An inch worm is at the bottom of a well n inches deep. It has enough ener

HDU1049 Climbing Worm

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

HDU-1049-Climbing Worm(C++ &amp;&amp; 编程初学者的题......)

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14196    Accepted Submission(s): 9560 Problem Description An inch worm is at the bottom of a well n inches deep. It has enough ener

OC中使用字典管理颜?

处理?程?件crayons.txt中的?本信息,?本内容是关于颜色的,每?都是?个颜?的信息,例如:Almond #EED9C4,前?个字符串是颜?色的名称,后?个字符串是颜色的16进制?值,处理?本完成如下需求: 1.使用字典管理所有的颜?,即字典中存储的是多个键值对,颜?名称为key,16进制颜?色值(不带#)是value. 2.取出所有的key,升序排列. 3.取出所有的value,按照排序后的key排列. 4.使?用?个新的字典管理颜色,对颜?进?分类管理,即:“A”,“B”,“C”..

zsc_寒假训练 6

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