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


    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
     
    Recommend
    We have carefully selected several similar problems for you:  1071 1170 1052 1051 1800 
     
    水题,又貌似是道数学题,注意题中的陷阱,有点像小时候玩过的脑筋急转弯。
     
    题意:一个虫子掉在了一个n长度深的井中,然后它每分钟可以爬u长度,然后要休息一分钟,在此期间它会掉下d长度,问最终爬出井需要多久。
     
    附上代码:
     
     1 #include <iostream>
     2 using namespace std;
     3 int main()
     4 {
     5     int t,n,m,i,j,s;
     6     while(cin>>s>>n>>m)
     7     {
     8         if(s==0&&n==0&&m==0)
     9             break;
    10         s-=n;       //最后一个n的长度只要1分钟
    11         t=s/(n-m)*2;    //每次爬行 爬的距离和滑下来的距离之差,并且需要2分钟
    12         if(s%(n-m)!=0)    //若除不尽,则多爬行两分钟
    13             t+=2;
    14         cout<<t+1<<endl;   //记得加上最后1分钟爬了n
    15     }
    16     return 0;
    17 }
  • 相关阅读:
    概率论与数理统计(3)
    平衡二叉树(AVL)实现(3)删除
    平衡二叉树(AVL)实现(1)
    利用C#2005实现数据表的基本操作
    用js计算时间差,得到比较人性化的结果
    WinForm 窗口最小化到托盘 notifyIcon
    wget 使用技巧
    使用javascript从url获取参数值
    OWC做电子表格和图表的试验
    C#中combobox 和TreeView控件属性、事件、方法收集
  • 原文地址:https://www.cnblogs.com/pshw/p/4814353.html
Copyright © 2011-2022 走看看