博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Climbing Worm
阅读量:4705 次
发布时间:2019-06-10

本文共 1384 字,大约阅读时间需要 4 分钟。

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
 
 
 
水题。
总长为n,上升一秒走u,休息一秒下降d.
相当于每两秒走(u-d);
先n-u,得到过了多少个u-d后超过n-u;
int t=(n-u)/(u-d);
        if(t*(u-d)<(n-u)) t++;
        t*=2;
        t++;
就是最后一秒可以一步到达~~~
代码:
#include
int main() {
int n,u,d; while(scanf("%d%d%d",&n,&u,&d),n) {
int t=(n-u)/(u-d); if(t*(u-d)<(n-u)) t++; t*=2; t++; printf("%d\n",t); } return 0; }

转载于:https://www.cnblogs.com/to-creat/p/4929387.html

你可能感兴趣的文章
Mysql 模糊匹配(字符串str中是否包含子字符串substr)
查看>>
python:open/文件操作
查看>>
流程控制 Day06
查看>>
Linux下安装Tomcat
查看>>
windows live writer 2012 0x80070643
查看>>
tomcat 和MySQL的安装
查看>>
git常用操作
查看>>
京东SSO单点登陆实现分析
查看>>
u-boot启动第一阶段
查看>>
MySQL批量SQL插入性能优化
查看>>
定义列属性:null,default,PK,auto_increment
查看>>
用户画像展示
查看>>
C#中StreamReader读取中文出现乱码
查看>>
使用BufferedReader的时候出现的问题
查看>>
批处理文件中的路径问题
查看>>
hibernate出现No row with the given identifier exists问题
查看>>
为什么wait()和notify()属于Object类
查看>>
配置NRPE的通讯
查看>>
匹配两个空格之间的字符。。。
查看>>
CSS 文字溢出 变成省略号 ...
查看>>