zoukankan      html  css  js  c++  java
  • (HDOJ 1049)Climbing Worm


     Climbing Worm

    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
     

     AC code:

     #include<stdio.h>

    int main()
    {
         
    int n,u,d;
         
    int count,i,s;
         
    while(scanf("%d %d %d",&n,&u,&d)&&n)
         {
             
    if(n<=u) s=1;
             
    else
             {
                 
    for(i=1; ; i++)
                 {
                     
    if(n-(u-d)*i<=u)
                     
    break;
                     }
                     count
    =i;
                     s
    =2*count+1;

             }
             printf(
    "%d\n",s);
            }
         
    return 0;
    } 

    作者:cpoint
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    移动端适配问题
    面试题
    c++学习之路
    es6特性
    ndoe安装依赖注意的问题
    如何阻止button默认的刷新页面操作
    npm 全局安装模块,出现XXX不是内部或外部命令解决方法
    .Net MVC系统源码与教学视频《资源分享系列6》
    Javascript书店课程设计《资源分享系列4》
    Python教程与源码《资源分享系列4》
  • 原文地址:https://www.cnblogs.com/cpoint/p/2015327.html
Copyright © 2011-2022 走看看