zoj1494 暴力模拟 简单数学问题
来源:互联网 发布:usr share mysql 编辑:程序博客网 时间:2024/06/05 10:33
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
题目大意:
一只蜗牛要从爬上n英寸高的地方,他速度为u每分钟,他爬完u需要休息1分钟,且他休息时下滑d英寸,问他什么时候爬出去。
数据小,可以模拟。
while(~scanf("%d%d%d",&n,&u,&d),n||u||d){int h=0;int ans=0;while(h<n){ans++;h+=u;if(h >=n)break;ans++;h-=d;}printf("%d\n",ans);}
当数据大起来时,不妨想想公式。
个人思路,感谢指点纠正。
1:答案肯定是奇数(因为第一次是向上,最后一次也是向上,当然中间向下是偶数次)。
2:第一次单出来,后面以一上爬加一下滑为一个单位。
如 10 3 1 上行 汇总
第一天: 3 3
第二,三天 2 5
第四,五天 2 7
第六,七天 2 9
第八,九天 2 11(到达)
因为2*n和2*n+1(2*n-1还未到达)是先下后上,所以不会出现2*n就到到的情况。
#include<cstdio>#include<cstdlib>#include<iostream>#include<math.h>#include<string>using namespace std;int a,b,c;void _solve(){int ans;ans=1;a-=b;if(a<0) {cout<<ans<<endl;return ;}//第一天结束 int temp;if(a%(b-c)==0) temp=a/(b-c);else temp=a/(b-c)+1;//尾巴任然算一个单位 temp*=2;//除了第一天,后面两天为一个单位 ans+=temp;cout<<ans<<endl;return ;}int main(){ while(cin>>a>>b>>c) if(!a&&!b&&!c) return 0; else _solve(); return 0;}
- zoj1494 暴力模拟 简单数学问题
- zoj1494
- zoj1494
- zoj1494
- zoj--3935--2016(暴力模拟)(数学)
- 2017模拟赛-本科组 (暴力+DFS+数学)
- ZOJ 3827 简单数学推导+简单模拟
- 染色问题 简单数学
- 简单的数学问题
- 简单问题窥见数学
- 简单的数学问题
- Codefroces 32C (简单模拟+数学)
- [水]ZOJ1494
- NBUT - 1647 又一道简单题 (暴力模拟)
- 九度 1363 欢乐打扑克 【简单水题暴力模拟】
- 一个简单的数学问题
- HDU 1099 Lottery (数学问题模拟)
- Separating Pebbles数学,暴力
- [HDU 5383] Yu-Gi-Oh!
- HDU 4398 STL + 贪心
- 顺序存储的二叉树的最近的公共祖先问题
- Android基础_常见Adapter/ExpandListView/Dialog/PopupWindow/自定义AlertDialog/单元测试/转移文件到SD卡(四)
- 进程与线程的关系
- zoj1494 暴力模拟 简单数学问题
- squid3正向代理
- 读书笔记:利用Python进行数据分析【第一章:准备工作】
- 函数式编程
- Fragment 生命周期完整版
- C++(7)模板与泛型编程
- MySQL性能分析之explain的使用
- CodeBlock一些使用技巧
- Codeforces-734E Anton and Tree(树的直径)