hdu 1049

原创 2018年04月16日 20:54:25

Climbing Worm

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


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
题目注意:1.不满一分钟按一分钟算;
         2.当向上爬是恰好到达顶端,那么虫子直接就上去了,没有休息还下滑的情况发生;
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;

typedef long long LL;

int main(){
    int n, u, d;
    while(scanf("%d", &n) != EOF && n){
            scanf("%d%d", &u, &d);
            int cnt = 0, h = 0;
            h = u;
            cnt++;
            while(h < n){
                h -= d;
                cnt++;
                h += u;
                cnt++;
            }
            cout << cnt << endl;
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/guihaiyuan123/article/details/79966331

杭电ACM1049的解题报告

Climbing Worm Problem Description An inch worm is at the bottom of a well n inches deep. It has enou...
  • Aqin556
  • Aqin556
  • 2016-07-27 11:02:50
  • 580

HDU1049(解题报告)

Climbing Worm                                                    Time Limit:1000MS    Memory Limit:...
  • u013447865
  • u013447865
  • 2014-01-14 22:18:11
  • 731

HDU1049

HDU1049 Climbing Worm 一只蠕虫在深n英寸的井中,它每分钟会向上爬u英寸,然后它会休息1分钟并且下滑d英寸,现在要求它要多少分钟能到达进口(它就算刚到井口然后会下滑,也算它到达井...
  • u013480600
  • u013480600
  • 2014-02-14 12:21:25
  • 990

HDU 1049

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To...
  • u013171170
  • u013171170
  • 2014-04-30 18:34:55
  • 269

Hdu 1049

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...
  • wangming520liwei
  • wangming520liwei
  • 2014-10-22 22:21:47
  • 368

【HDU】 1049

Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...
  • hss1996
  • hss1996
  • 2017-11-21 22:08:05
  • 59

hihocoder 1049 后序遍历

题意:给出先序遍历和中序遍历,求出后序遍历的结果。 算法没什么,大家sho...
  • u010582475
  • u010582475
  • 2014-10-02 09:23:47
  • 1049

HDU 1049

#include using namespace std; int main(){ int n,u,d,sum; while(cin>>n>>u>>d&&n){ ...
  • major_zhang
  • major_zhang
  • 2016-04-07 16:23:07
  • 186

登录MYSQL时候报错, 报错信息: ERROR 1049 (42000): Unknown database 'xxxxxx'

登录MYSQL时候报错, 报错信息: ERROR 1049 (42000): Unknown database 'xxxxxx'
  • MeJustOny
  • MeJustOny
  • 2017-04-12 18:55:59
  • 3335

django.db.utils.OperationalError: (1049, "Unknown database 'djangodb'")

DATABASES = {     'default': {         'ENGINE': 'django.db.backends.mysql',         'NAME':  'my...
  • darongzi1314
  • darongzi1314
  • 2016-07-11 14:18:14
  • 3538
收藏助手
不良信息举报
您举报文章:hdu 1049
举报原因:
原因补充:

(最多只允许输入30个字)