HUD 1049 Climbing Worm
来源:互联网 发布:淘宝主图视频怎么添加 编辑:程序博客网 时间:2024/06/17 14:55
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
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 1
20 3 1
0 0 0
Sample Output
17
19
这道题我是找规律模拟出来的
#include<stdio.h>#include<iostream>using namespace std;int main(){ int n,u,d,i,j; while(~scanf("%d",&n),n) { scanf("%d%d",&u,&d); int x=u-d; int sum=0,s=0; while(1) { if(s<n-u) { s+=x; sum+=2; } if(s>=n-u&&s<n) { s+=u; sum++; } if(s>=n) break; } printf("%d\n",sum); } return 0;}
- HUD 1049 Climbing Worm
- 1049 Climbing Worm
- HDU 1049 Climbing Worm
- hdoj 1049 Climbing Worm
- 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
- HDOJ 1049 Climbing Worm
- Climbing Worm- hdu-1049
- hd 1049 Climbing Worm
- hdu 1049 Climbing Worm
- Java中的串行化
- 零基础如何学爬虫技术?
- 开发 - 时间交叉
- Picasso的使用
- SYU新人提高90题1(基础题)
- HUD 1049 Climbing Worm
- swift _ 控制流
- android学习路径及开源控件
- 调试技巧——宏定义开关和printf
- 组合模式
- 怎么运行别人的React-Native项目(android端)
- 智能指针的简单总结
- 使用JSON和Flask后台交换数据
- Doxygen + Graphviz windows下安装配置(图解)