zoj1494 暴力模拟 简单数学问题
2017-09-27 21:06
447 查看
Climbing Worm
Time Limit:
2 Seconds Memory Limit:65536 KB
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英寸,问他什么时候爬出去。
数据小,可以模拟。
当数据大起来时,不妨想想公式。
个人思路,感谢指点纠正。
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就到到的情况。
Time Limit:
2 Seconds Memory Limit:65536 KB
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 暴力模拟 简单数学问题
- zoj--3935--2016(暴力模拟)(数学)
- ZOJ 3827 简单数学推导+简单模拟
- 算法入门\简单模拟\竖式问题
- 粒子群算法针对数学规划问题的简单应用
- 蓝桥杯 基础练习 2n皇后问题 (简单dfs暴力+优化剪枝)
- FJUT 3101 Home_W的简单问题3 数学 因子和问题
- 简单的数学问题
- HDU 1099 Lottery (数学问题模拟)
- 两个简单的小学数学问题
- 高精度问题之大数相加(原来就是用字符串相加,模拟手算这么简单!)
- 括号配对问题 (栈模拟 简单题)
- 统计工龄 模拟EXCEL排序 银行排队问题之单队列多窗口问题 银行业务队列简单模拟 堆栈操作合法性 两个有序序列的中位数
- 简单的数学问题
- 关于2014年考研数学冲刺模拟试题的编制问题
- 九度 1363 欢乐打扑克 【简单水题暴力模拟】
- 关于2014年考研数学冲刺模拟试题的编制问题(IV)
- ZOJ 3804 YY's Minions (简单模拟)
- FJUT 3101 Home_W的简单问题3 数学 因子和问题
- ZOJ 3939The Lucky Week<模拟/暴力>