关闭

Climbing Worm

212人阅读 评论(0) 收藏 举报
Climbing Worm

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


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
//杭电1049 Climbing Worm
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main()
{
    int n,u,d;
    int t,i;
    while(scanf("%d %d %d",&n,&u,&d)!=EOF&&n!=0)
    {
        if(n<=u)//高度小于每分钟爬的高度时,只需1分钟//<=很重要,有一个错误,最终发现在这
        {
            t=1;
        }
        else
        {
            for(i=1; ;i++)
            {
                if(n<=(u-d)*i+u)
                    break;
            }
            t=i*2+1;
        }
         printf("%d\n",t);
    }
    return 0;
}
//杭电1049 Climbing Worm
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main()
{
    int n,u,d;
    int t,s;
    while(scanf("%d %d %d",&n,&u,&d)!=EOF&&n!=0)
    {
        t=0;s=0;
        while(1)
        {
            s+=u;
            t++;
            if(s>=n)
            break;
            s-=d;
            t++;
        }
        printf("%d\n",t);
    }
    return 0;
}

 

 
0
0
查看评论

「HD_ACM」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 ...
  • Simple_Bottle
  • Simple_Bottle
  • 2015-05-03 19:17
  • 893

【hdoj_1049】Climbing Worm

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1049 以 上升-下降 一次为一个周期,一个周期时间为2分钟,每个周期上升距离为(u-d)。先只考虑上升,再只考虑下降。先上升n/u次,再下降n/u次,这样保证不会超过井口,这样上升和下降各n/u次之后离井口...
  • ten_sory
  • ten_sory
  • 2016-06-23 11:13
  • 292

Climbing Worm(贪心)

C - Climbing Worm Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u SubmitStatus Description An inch worm is at the...
  • qq_32680617
  • qq_32680617
  • 2016-07-08 08:15
  • 234

Climbing Worm

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14065   &...
  • l15738519366
  • l15738519366
  • 2015-05-31 14:52
  • 474

hdu 1049 Climbing Worm

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12245...
  • fyxz1314
  • fyxz1314
  • 2014-08-03 16:50
  • 635

H - Climbing Worm解题报告

H - Climbing Worm Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &...
  • princeyuaner
  • princeyuaner
  • 2012-04-18 18:34
  • 367

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

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14196...
  • qq_16542775
  • qq_16542775
  • 2015-06-14 13:32
  • 666

浙江大学题解ZJU_ALL

  • 2010-07-19 19:56
  • 835KB
  • 下载

HDU_1049 Climbing Worm 【贪心】

题目信息: 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 minu...
  • qq_36345036
  • qq_36345036
  • 2017-04-11 07:42
  • 102

HDOJ 1049-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 climb...
  • qq_29600137
  • qq_29600137
  • 2015-12-29 17:15
  • 245
    个人资料
    • 访问:70640次
    • 积分:1343
    • 等级:
    • 排名:千里之外
    • 原创:149篇
    • 转载:8篇
    • 译文:0篇
    • 评论:5条
    最新评论