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    Accepted Submission(s): 9560

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

Recommend

We have carefully selected several similar problems for you:  1021 1019 1108 1071 1009

没什么好解释的,题目意思很明确,讲的是一个小虫子想要爬出水井的故事!(我也得尽快爬出水井......)

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,u,d;
    while(scanf("%d%d%d",&n,&u,&d)!=EOF)
    {
        if(n==0)
            break;
        int s=0,t=0;
        while(s<n)
        {
            s+=u;
            t++;
            if(s>=n)
            {
                break;
            }
            s-=d;
            t++;
        }
        printf("%d\n",t);
    }
    return 0;
}
时间: 2024-11-02 14:11:24

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

【贪心专题】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【水!水!水!】【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

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

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

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

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

老菜鸟趣谈:对编程初学者的一些建议

对编程初学者的建议 PS:这篇文章我只在微信公众号和头条网发布了,忘了在博客里发. 我是程序员,我为程序员代言. 现在真的是编程的黄金年代,程序员从来不曾这样供不应求,特别是嵌入式领域. 现在哪怕是银行,也需要几个程序员,负责网站的编写,App编写,数据库管理,服务器管理,安全管理,等等. 所以学会编程你就有福了,真的不是夸张,我到目前还是菜鸟一个,真的越学习越感到自己了解得就如牛顿所说:“我只不过是在海边捡到了几块贝壳的孩子,尚且有些许欢喜,岂知知识的海洋正在眼前”. 也没有一个时代像现在这样

《编程初学者学什么语言好》读后感

编程语言种类数不胜数,作为一个编程初学者还真是不知道学什么好.学校要求先学习基本的C语言,可是我觉得好难不好学,基本的学不好我也很苦恼.再加上本身就不会自主学习,花在学习上的时间也是少之又少.后来阅读了<我是一只IT小小鸟>也发现不能什么都学,应该专注学习一门语言,而且还要学得精.后来老师推荐我学习Python,我了解了一下确实语法和库更丰富,上手更容易,使用更方便.读了这篇文章之后更加坚定了我要学习Python的决心. 不过也了解到学习C语言的重要性,简单直接而且基础,今天很认真的打了一大串

给编程初学者的21条忠告

学习编程,几行箴言: 1,编程不难,但也不易 2,高薪,只会留给有水平的人;机会,只留给有准备的人 3,理解不了的先记忆 4,不要被一个复杂的单词所吓退 5,没有几万行代码量,编程你肯定学不会 6,简单的是控件,复杂的是思想 7,没有人天生就会编程,它是不断编码,积累,总结的产物 8,看看招聘的要求,你就知道自己几斤几两 9,浪费时间,就是降低自己的工资,贬低自己的价值 10,代码是敲出来的,能力是学出来的 11,学的越多,就发现自己不会的也越多 12,按部就班的编程模式不应成为你编程的绊脚石