hdoj1049
来源:互联网 发布:debian 8 切换php版本 编辑:程序博客网 时间:2024/05/22 06:44
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
代码:
#include<stdio.h>int main(){int n,u,d,T,i;while(scanf("%d%d%d",&n,&u,&d)!=EOF){T=0;if(n==0&&u==0&&d==0)break;for(i=0;;i++){if(n<=0){printf("%d\n",T);break;}else{n-=u;T++;if(n<=0){printf("%d\n",T);break;}n+=d;T++;}}}return 0;}
思路:简单的贪心题,蜗牛滑坡…………
0 0
- hdoj1049
- hdoj1049
- hdoj1049 Climbing Worm
- hdoj1049解题报告
- HDOJ1049 Climbing Worm
- hdoj1049简单题、模拟题
- hdoj1049 Climbing Worm(小学数学题)
- 欢迎使用CSDN-markdown编辑器
- Handlebars.js 模板引擎
- memcached—协议
- 自定义ImageView实现地图(一)
- HDU 1568 Fibonacci【数学】
- hdoj1049
- Android RecyclerView的使用
- git rebase 后找回消失的commit
- <LeetCode OJ> 328. Odd Even Linked List
- 关于Android Studio如何导入library project
- ♥Vijos 1242-邮局问题【经典DP】
- UIWebView的前进和后退功能
- 人工智能-搜索算法
- 数据标准化