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 
  • 相关阅读:
    每日一题_191101
    阿基米德三角形(交互式学件)
    2018四川高考数学(全国卷3)理科21题以泰勒公式为命题背景(同时深挖去年高考题)和它的另类解法的瞎谈
    给老谢画的图(平面几何中的动点与最值问题)
    2018四川高考文科21题
    数学解题的思维过程
    Qt Creator 模块QtSql
    QT Creator快捷键不能用
    QT 随机数
    C++ 4 种具有更 为准确语义的新强制转换类型
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2583559.html
Copyright © 2011-2022 走看看