hdu-1049-Climbing Worm

来源:互联网 发布:网络教育 档案 拆开 编辑:程序博客网 时间:2024/05/30 02:26

http://acm.hdu.edu.cn/showproblem.php?pid=1049

Climbing Worm

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20187    Accepted Submission(s): 13805


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 120 3 10 0 0
题意:一条虫子每分钟往上爬u英寸,爬一分钟休息一分钟,休息过程中下降d英寸,问多久可以爬出高度为n英寸的井。
如果最后一段距离不需要花一分钟,按一分钟算。
简单题啊,直接上代码= =
#include<iostream>#include<stdio.h>using namespace std;#define maxn 1000005int n;int main(){int n,u,d,ans;while(cin>>n>>u>>d){if(n==0){break;}int tmpu=u-d;int tmpn=n;tmpn=n-u;if(tmpn%tmpu){ans=2*(tmpn/tmpu+1)+1;}else {ans=2*(tmpn/tmpu)+1;}cout<<ans<<endl;}}

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 苹果手机下载的游戏闪退怎么办 宝宝两岁了不怎么爱拉大便怎么办? 小狗脖子发硬疼的直叫怎么办 厨房里有很多小虫子围着鸡蛋怎么办 狗生小狗后几天不吃饭怎么办 还没满月的小兔子突然死了怎么办 宝宝小鸡被蚊子咬后肿得很大怎么办 不知道是哪知兔子下的小兔怎么办 兔子生完小兔不吃东西了怎么办 人工喂养七天的小羊拉希怎么办 仔兔出生3天吃过奶就尿怎么办 小兔子买回来两天不拉屎怎么办 大狗生了小狗把小狗咬死了怎么办 狗妈妈一直咬小狗的脐带怎么办 狗狗体内驱虫驱不干净怎么办 打老鼠脚被老鼠咬了怎么办 天正画的cad打开显示空白怎么办 苹果手机信息被拉进群聊怎么办 空调的控制线的报验资料怎么办 窗窗户罩子护栏上的瓦楞板怎么办 酸洗好的带钢容易返锈怎么办 化肥撤到小树苗上现在变黑了怎么办 尿素液烧的太慢了怎么办 天堂鸟肥料施多了黄叶了怎么办 死水塘养的鱼每天在死怎么办 北京的阿姆斯肥把苗都烧死了怎么办 纱窗被老鼠咬了个洞 怎么办 低电量模式下动态墙纸不能用怎么办 吃的包装袋执行标准错了怎么办 退换东西的时候外包装坏了怎么办 闲鱼买家以与描述不符退货怎么办 闲鱼买家申请退款又签收了怎么办 店铺买的手机是拆开过的怎么办 卖家以包装破损拒收快递怎么办 车辆迁出落户信封被自己拆开怎么办 快递签收了发现物品坏了怎么办 快递签收后发现货坏了怎么办 闲鱼退货有破损卖家要求赔偿怎么办 邮政快递收货后发现快递破损怎么办 中通把包裹发到别的省份去了怎么办 寄快递没拿单子但东西破损了怎么办