AcmStep Chapter One Section Two—Climbing Worm
2011-08-16 23:15
375 查看
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.#include <iostream> using namespace std; int main() { int n; cin>>n; while (n) { int u,v,current=0,min=0; cin>>u>>v; while (current<n) { min++; if (current+u>=n) { current+=u; cout<<min<<endl;; } else { min++; current+=u-v; } } cin>>n; } return 0; }
本题只有一个小地方需要注意一下,不要惯性思维了!
这或者只是一个幼稚的起步,但希望路过的大牛可以指点一二,从各方面都可以,包括编程风格等。
相关文章推荐
- Acm Step Chapter One Section Two—Rightmost Digit
- AcmStep Chapter One Section Two—Nasty Hacks
- AcmStep Chapter One Section One—A+B problem series
- HDU acm step:Chapter one section three(简单贪心)
- HDU's ACM Step Section One -- A+B for Input-Output Practice
- hdu ACM Step chapter 2
- [Objective-c基础教程] chapter one Before You Start & chapter two Extensions to C
- Finding all paths climbing stairs in one or two steps.
- chapter 2 section 2.4 The Tamworth Two
- WCF 4 Step By Step Chapter 10-12 Note (Reliable Sessions,ProgrammaticallyControlling, One-Way ...)
- ACMSTEP 1.2.5 IBM Minus One//超级水题
- 杭电 ACM Chapter One
- ACM STEPS——Chapter Two——Section One
- Memory space manipulating in Java(Section two:Process Memory Model on AIX part one-Terminologies)
- ACM Steps Chapter One
- UESTC_One Step Two Steps CDOJ 1027
- Chapter Two Hopes of Agnes Grey
- motorola scanner datasheet相关解释 One Discrete Length, Two Discrete Lengths,Length Within Range
- C# step by step 学习笔记8 CHAPTER 9 使用枚举和结构创建值类型
- ACM STEP 1.2.3 Nasty Hacks