• 【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 
  • 相关阅读:
    网络连接的基本概念,中继系统(网络)
    qnorm 函数 , with 函数(R)
    关于 paste 函数 (R)
    对数据的探索,数据框中是否有大于某个数的值,返回大于的具体的数值,或者数值的坐标(R)
    查看内存占用情况,查看进程,终止进程(cmd)
    查询校园网外网的ip
    二进制的减法(汇编)(数字电路)
    画出箱线图(R)
    排比句(文章写作)
    react中的TS理解
  • 原文地址:https://www.cnblogs.com/ismdeep/p/2583559.html
Copyright © 2020-2023  润新知