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

East Central North America 2002

水题。

总长为n,上升一秒走u,休息一秒下降d.

相当于每两秒走(u-d);

先n-u,得到过了多少个u-d后超过n-u;

int t=(n-u)/(u-d);
        if(t*(u-d)<(n-u)) t++;
        t*=2;
        t++;

就是最后一秒可以一步到达~~~

代码:

#include<stdio.h>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;}    

时间: 2024-10-16 13:14:44

Climbing Worm的相关文章

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

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

杭电OJ(HDU)-ACM Steps-Chapter Two-《Biker&#39;s Trip Odometer》《Climbing Worm》《hide handkerchief》《Nasty Hac》

1.2.1 Biker's Trip Odometer #include<stdio.h> #include<math.h> const double PI=acos(-1.0); /* 计算题,根据公式做就行,PI*d*r/(12*5280);res1/t*3600; Sample Input 26 1000 5 27.25 873234 3000 26 0 1000 Sample Output Trip #1: 1.29 928.20 Trip #2: 1179.86 1415

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

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

HDU1049 Climbing Worm【水题】

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1049 题目大意: 一直虫子掉在了一个长度为N米的井中,它每分钟向上爬u米,然后休息一分钟,休息期间会向下 掉d米,问:爬出井需要多久. 思路: 直接模拟即可.用time的奇偶来表示向上还是向下走. AC代码: #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> us

【贪心专题】HDU 1049 Climbing Worm (爬井趣题)

链接:click here~~ 题意: 题目大致意思是一个虫子掉在了一个n长度深的井中,然后它每分钟可以爬u长度,然后要休息一分钟,在此期间它会掉下d长度,问最终爬出井需要多久. 简单模拟: 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm> using namespace std; int ma

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