hdoj 1049 Climbing Worm
来源:互联网 发布:电影源码 编辑:程序博客网 时间:2024/05/01 22:04
Climbing Worm
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13179 Accepted Submission(s): 8883
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
坑我???我看的hdoj分类说这是贪心!
#include<stdio.h>int f(int h,int u,int d){ int climb=0; int sum=0; int i; while(1) { sum++; climb+=u; if(climb>=h) break; climb-=d; sum++; } return sum;} int main(){ int h,u,d; while(scanf("%d%d%d",&h,&u,&d)&&(h!=0||u!=0||d!=0)) { printf("%d\n",f(h,u,d)); } return 0;}
0 0
- hdoj 1049 Climbing Worm
- HDOJ 1049 Climbing Worm
- hdoj 1049 Climbing Worm
- HDOJ 1049 Climbing Worm
- hdoj 1049 Climbing Worm 【水题】
- hdoj 1049 Climbing Worm【贪心】
- HDOJ 1049-Climbing Worm【数学】
- [HDOJ 1049] Climbing Worm (基础题)
- hdoj 1049 climbing worm(小学数学题)
- hdoj 1045 Climbing Worm
- HDOJ Climbing Worm(Java)
- HDOJ Climbing Worm
- [hdoj试题]Climbing Worm
- HDOJ Climbing Worm
- ACM--虫子爬井--模拟--HDOJ 1049--Climbing Worm--水
- 1049 Climbing Worm
- HDU 1049 Climbing Worm
- 1049 Climbing Worm
- 推荐两款我一直在用的PC健康小软件
- BaseAdapter与CursorAdapter的结合使用举例
- C++面试题之string类
- PostgreSQL每日一贴-测试工具之pgbench
- 【sql 优化】union 、union all、or使用
- hdoj 1049 Climbing Worm
- 创建Cocos2d-x工程 cocos2dx-3.x 创建工程命令
- Ubuntu安装配置Mysql
- 走进CSDN
- CentOS 7 巨大变动之 systemd 取代 SysV的Init
- ACM 阶乘的精确值
- Java五道输出易错题解析(进来挑战下)
- supervisord管理进程详解
- jboss7支持中文URI