zoukankan      html  css  js  c++  java
  • 【hdu 1049 Climbing Worm】

    Climbing Worm

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


    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
     
     
     1 // Project name : 1049 ( Climbing Worm ) 
     2 // File name    : main.cpp
     3 // Author       : Izumu
     4 // Date & Time  : Mon Jul  9 18:50:46 2012
     5 
     6 
     7 #include <iostream>
     8 using namespace std;
     9 
    10 const bool goup   = true;
    11 const bool godown = false;
    12 
    13 void CCalClimbingTime(int depth, int up, int down)
    14 {
    15     // start cal climbing time
    16     int time = 0;
    17     if (depth == 0)
    18     {
    19         time = 1;
    20     }
    21     else
    22     {
    23         bool go = goup;
    24         while (depth > 0)
    25         {
    26             if (go == goup)
    27             {
    28                 depth -= up;
    29                 go = godown;
    30                 time++;
    31             }
    32             else
    33             {
    34                 depth += down;
    35                 go = goup;
    36                 time++;
    37             }
    38         }
    39     }
    40 
    41     cout << time << endl;
    42 }
    43 int main()
    44 {
    45     int depth, up, down;
    46     while (cin >> depth >> up >> down && depth + up + down)
    47     {
    48         CCalClimbingTime(depth, up, down);
    49     }
    50     return 0;
    51 }
    52 
    53 // end 
    54 // ism 
  • 相关阅读:
    memset函数具体说明
    几种常见模式识别算法整理和总结
    GridView编辑删除操作
    Linux的文件夹配置
    Js apply 方法 具体解释
    深入分析C++引用
    Sizzle.selectors.relative [ 源代码分析 ]
    中文分词国内现状
    [数字图像处理]图像去噪初步(2)--非线性滤波器
    线程间共享数据的一个样例
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2583559.html
Copyright © 2011-2022 走看看