HDU 2832 Snail’s trouble 数学题
来源:互联网 发布:阿里巴巴旗下所有软件 编辑:程序博客网 时间:2024/06/07 17:35
Snail’s trouble
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 729 Accepted Submission(s): 368
Problem Description
Once upon a time, there was a poor snail. Every day, it tried very hard to crawl forward, while there was a keeper who’d like to maltreat this poor little snail. The snail was crawling on a one-meter rubber band at first, and it can move on k cm every minute. But after that, the keeper stretches the rubber band quickly, and it would be elongated one meter, during that the distances ratio between the snail and the two endpoints remain unchanged. In the next minute, little snail tried to keep moving forward again.
“Can I finally get to the endpoint?”
The snail often asked himself such a question because he was afraid he would never succeed. Now, we hope you can tell this poor snail when he would reach the endpoint.
“Can I finally get to the endpoint?”
The snail often asked himself such a question because he was afraid he would never succeed. Now, we hope you can tell this poor snail when he would reach the endpoint.
Input
Every line of the input contains an integer number k, indicating that the snail moved forward k cm every minute. (5 <= k <= 100)
Output
Output an integer t, indicating that the snail doesn’t get to the endpoint until t-1 minutes later, while t minutes later, it finally succeed.
Sample Input
10100
Sample Output
123671
/*HDU 2832 数学题 题意,一开始一条路长100cm,蜗牛每分钟爬kcm,之后把路拉长100cm,左右拉长,并且蜗牛所在位置与两端距离比不变, 接着蜗牛再爬kcm,问蜗牛什么时候能爬到终点。 全路程为1,按比例求和,则我们第1分钟就爬了k/100的距离,第二分钟总距离200,爬了k/200距离,第n分钟,总共爬了(k/100*(1+1/2+1/3...1/n))>=1,求n的最小值 */#include<iostream>#include<stdio.h>using namespace std;#define N 101#define eps 1e-14int ans[N];void getAns(){int i,j;double res,c;for(i=5;i<=100;i++){//res=i*1.0/100; 这个没过掉,为啥呢?哪里损失了精度 //c=0;//for(j=1;;j++)//{//c+=1.0/j;//if((res*c)>=1)//break;//}res=100.0/i;//看了别人的精度控制 c=0;for(j=1;;j++){c+=1.0/j;if(c-res>-eps)break;}ans[i]=j;}}int main(){int k;getAns();while(scanf("%d",&k)!=EOF){printf("%d\n",ans[k]);}return 0;}
0 0
- HDU 2832 Snail’s trouble 数学题
- HDU 2832 Snail’s trouble(数学题)
- hdu 2832 Snail’s trouble
- HDU 2832 Snail’s trouble [模拟]
- HDU 2832-Snail’s trouble(分治)
- HDU 1302 The Snail(简单数学题)
- 【优秀数学题】HDU 1302——The Snail
- hdu 2832(数学题)
- hdu 2114 Calculate S(n) 简单数学题
- HDU 4488 Faulhaber’s Triangle (数学题)
- Trouble HDU
- king's trouble II
- king's trouble II
- king's trouble I
- king's trouble I
- hdu 3876 A pupil’s problem(简单数学题)
- hdu 2603 Wiskey's Power(数学题),待改正
- hdu 1165 Eddy's research II(数学题,递推)
- intellij idea的插件开发小结
- Python - DMX
- 分层设计测试用例
- UVA - 11806 Cheerleaders
- 菱形
- HDU 2832 Snail’s trouble 数学题
- c++电子书籍下载
- iOS学习07---NSSet
- AFHTTPRequestOperationManager网络请求的时候添加一个菊花
- Java基础_网络编程
- Android强制设置横屏或竖屏
- struts2配置默认首页
- Json解析实例Tomcat服务器
- 简单编程(十六)编写递归方法返回x和y的最大公约数