Climbing Worm
2015-05-31 14:52
309 查看
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14065 Accepted Submission(s): 9500[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
10 2 1 20 3 1 0 0 0
[align=left]Sample Output[/align]
17 19
#include<stdio.h>
main()
{
int n,u,b,i,m;
while(scanf("%d%d%d",&n,&u,&b)!=EOF)
{
m=0;
if(n==0&&u==0&&b==0)
break;
else
for(i=0;i<=n;)
{
i=i+u,m++;
if(i>=n)
break;
i=i-b,m++;
}
printf("%d\n",m);
}
return 0;
}
相关文章推荐
- Hadoop学习笔记(五)---HDFS shell操作
- 十二周——多态性——阅读项目(2)
- BZOJ 1050: [HAOI2006]旅行comf( 并查集 )
- java线程中run和start方法的区别
- JavaWeb:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
- Internal Sorting: Natural Two-way Merge Sort: Sorting by Merging
- 浅谈iOS面对对象之继承
- [实用技巧] 永久改键软件SharpKeys, 超级好用
- Android JNI编程学习
- SGU119 Magic Pairs
- Android ListView 图片异步加载和图片内存缓存
- 【STL源码剖析读书笔记】自己实现priority_queue之MyPriorityQueue
- MVC入门——详细页
- 【STL源码剖析读书笔记】自己实现priority_queue之MyPriorityQueue
- 记事本(查找与替换)
- @Factory和@DataProvider的区别
- windows 下 jdk tomcat7配置
- "晴天"天气app的开源库逐步学习(二)
- C++的内存模型和名称空间
- java文件读取全了解