0
点赞
收藏
分享

微信扫一扫

HDU 2832 Snail’s trouble 数学题


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.


 


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


10 100



Sample Output


12367 1


/*
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-14
int 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 条评论