HDOJ Climbing Worm(Java)
来源:互联网 发布:sqlserver修改sa密码 编辑:程序博客网 时间:2024/05/02 01:50
Climbing Worm
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11811 Accepted Submission(s): 7921
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
1719AC代码:水题不解释!!!import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(true){ int n = in.nextInt(); int u = in.nextInt(); int d = in.nextInt(); int inches = 0; int minutes = 0; if(n == 0) break; while(inches < n){ inches += u; minutes++; if(inches >= n) break; minutes++; inches -= d; } System.out.println(minutes); } }}
0 0
- HDOJ Climbing Worm(Java)
- hdoj 1049 Climbing Worm
- hdoj 1045 Climbing Worm
- HDOJ 1049 Climbing Worm
- HDOJ Climbing Worm
- hdoj 1049 Climbing Worm
- [hdoj试题]Climbing Worm
- HDOJ 1049 Climbing Worm
- HDOJ Climbing Worm
- hdoj 1049 Climbing Worm 【水题】
- hdoj 1049 Climbing Worm【贪心】
- HDOJ 1049-Climbing Worm【数学】
- [HDOJ 1049] Climbing Worm (基础题)
- HDOJ---ACMSteps---1.2.2Climbing Worm
- hdoj 1049 climbing worm(小学数学题)
- Climbing Worm
- Climbing Worm
- Climbing Worm
- poj 2240
- 用OpenSceneGraph实现的NeHe OpenGL教程 - 第三十七课
- 【分享】利用Apache的Htaccess Files命令限制访问文件类型,Files正则
- iOS的手势识别模型
- 禁止IE兼容模式
- HDOJ Climbing Worm(Java)
- Eclipse下新建一个tld文件
- 0-1背包
- 笔记35--ListView/GridView/ExpandableListView注意事项
- 云南被指派大批警察抢走中弹身亡村民遗体
- 黑马程序员_OC_内存管理
- 黑马程序员——学习日记20 java高新技术(上)
- Java中的Serializable浅谈,只是浅谈
- MongoDB与JAVA CRUD