hdu 1049 Climbing Worm
来源:互联网 发布:微信运动添加数据来源 编辑:程序博客网 时间:2024/05/17 02:08
Climbing Worm
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12260 Accepted Submission(s): 8268
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
Sample Output
1719
题意:一个虫子掉在了一个n长度深的井中,然后它每分钟可以爬u长度,然后要休息一分钟,在此期间它会掉下d长度,问最终爬出井需要多久。
#include <iostream>#include <cstdio>using namespace std;int main(){ int n,u,d; int ans; while (cin>>n>>u>>d &&(n || u || d)) { ans=0; ans++; n-=u; while (n>0) { n+=d; ans++; n-=u; ans++; } cout<<ans<<endl; } return 0;}
0 0
- HDU 1049 Climbing Worm
- hdu-1049 Climbing Worm
- HDU 1049 ( Climbing Worm )
- HDU 1049 Climbing Worm
- HDU 1049 Climbing Worm
- hdu 1049 Climbing Worm
- HDU 1049 Climbing Worm
- HDU--1049 -- Climbing Worm
- hdu-1049-Climbing Worm
- hdu 1049 Climbing Worm
- Climbing Worm- hdu-1049
- hdu 1049 Climbing Worm
- hdu 1049 Climbing Worm
- hdu 1049 Climbing Worm
- HDU 1049 Climbing Worm
- HDU 1049 Climbing Worm
- HDU 1049 Climbing Worm
- HDU 1049 Climbing Worm
- Linux下进程间通信
- 【读书札记】建立第一个Web项目
- 产品经理们 什么叫工作到位?很深刻
- linux下snmp的安装和配置
- HDU4832
- hdu 1049 Climbing Worm
- uva 10617 - Again Palindrome
- uitextfield 限制输入位数
- JSON字符串转List
- qq群成员群发软件
- DFS【生日礼物】
- 数组大折腾2
- qsort bsearch 函数用法 小例
- 《语义网基础教程》学习笔记(二)