zoj1494 暴力模拟 简单数学问题
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英寸,问他什么时候爬出去。
数据小,可以模拟。
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 暴力模拟 简单数学问题的更多相关文章
- hdu_1006 Tick and Tick(暴力模拟)
hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...
- 洛谷试炼场-简单数学问题-P1088 火星人
洛谷试炼场-简单数学问题 A--P1088 火星人 Description 人类终于登上了火星的土地并且见到了神秘的火星人.人类和火星人都无法理解对方的语言,但是我们的科学家发明了一种用数字交流的方法 ...
- bnuoj 20832 Calculating Yuan Fen(暴力模拟)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832 [题意]: 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符 ...
- NS2仿真:使用NS仿真软件模拟简单网络模型
NS2仿真实验报告1 实验名称:使用NS仿真软件模拟简单网络模型 实验日期:2015年3月2日~2015年3月7日 实验报告日期:2015年3月8日 一.实验环境(网络平台,操作系统,网络拓扑图) 运 ...
- POJ 1013 小水题 暴力模拟
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35774 Accepted: 11 ...
- HDU 5073 Galaxy (2014 Anshan D简单数学)
HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...
- 洛谷试炼场-简单数学问题-P1403 [AHOI2005]-因数
洛谷试炼场-简单数学问题 P1403 [AHOI2005]约数研究 Description 科学家们在Samuel星球上的探险得到了丰富的能源储备,这使得空间站中大型计算机"Samuel I ...
- 洛谷试炼场-简单数学问题-P1045 麦森数-高精度快速幂
洛谷试炼场-简单数学问题 B--P1045 麦森数 Description 形如2^P−1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果PP是个素数,2^P-1 不一定也是素数.到19 ...
- hihoCoder #1871 : Heshen's Account Book-字符串暴力模拟 自闭(getline()函数) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction B) 2018 ICPC 北京区域赛现场赛B
P2 : Heshen's Account Book Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Description H ...
随机推荐
- 201521123064 《Java程序设计》第7周学习总结
1. 本章学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 参考资料: XMind 2. 书面作业 Q1:ArrayList代码分析 1.1 解释ArrayList的contains源 ...
- 201521044152<java程序设计>第一周学习总结
本周学习总结 java开发时间虽然很短,但是发展迅速,已成为现在非常流行的一门语言,很开心能有幸学习java.第一周学习了java的平台,运行环境jdk以及jrt等等新名词,还了解了eclipse的基 ...
- 如何将ubuntu文件夹中文名改为英文
其实我已经忍了很久. ubuntu在中文界面下面,自动创建了"桌面","文档",图片 .公共的 .下载. 音乐. 视频等中文目录. 在命令行下操作的时候,要么切 ...
- java 课程设计 购物车系统 个人
Q1.团队课程设计博客链接 团队博客 Q2.个人负责模块或任务说明 我主要负责main函数的编写和系统中瞎看功能代码的编写. Q3.自己的代码提交记录截图 main函数代码如下: public sta ...
- 201521123031 《Java程序设计》 第十周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. 2. 书面作业 本次PTA作业题集异常.多线程 1.finally 题目4-2 1.1 截图你的提交结果(出 ...
- 解决liblzo2.so缺失
系统:CentOS5.8 提示错误: error while loading shared libraries: liblzo2.so.2: cannot open shared object fil ...
- video标签
Video标签的使用 Video标签含有src.poster.preload.autoplay.loop.controls.width.height等几个属性, 以及一个内部使用的标签<sour ...
- eclipse:eclipse for java EE环境下如何配置tomcat服务器,并让tomcat服务器显示在控制台上,将Web应用部署到tomcat中
eclipse环境下如何配置tomcat 打开Eclipse,单击"Window"菜单,选择下方的"Preferences". 单击"Server& ...
- Hyperledger Fabric 1.0 从零开始(六)——创建Fabric多节点集群
4:创建Fabric多节点集群 4.1.配置说明 首先可以根据官方Fabric自带的e2e_cli列子中的集群方案来生成我们自己的集群,与案例不同的是我们需要把容器都分配到不同的服务器上,彼此之间通过 ...
- 在windows下安装flex和bison
学习Stellar-core 需要依赖项flex .bison .gcc三个依赖项 下载得网址:链接: https://pan.baidu.com/s/1mitCLcs 密码: 3jaj 通过 w ...