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 }
  • 相关阅读:
    kube-apiserver
    深度学习三:卷积神经网络
    深度学习二:概率和反向传播的变种
    深度学习一:深度前馈网络和反向传播
    Knowledge 1:Propositional Logic 命题逻辑基础及符号
    评估方法:留出法、交叉验证法、自助法、调参与最终模型
    你曾这样问过
    套路总结
    NOI2020游记
    curl不是内部或外部命令,也不是可运行的程序或批处理文件
  • 原文地址:https://www.cnblogs.com/pshw/p/4814353.html
Copyright © 2011-2022 走看看