Description
Onceupon a time, there was a poor snail. Every day, it tried very hard to crawlforward, while there was a keeper who’d like to maltreat this poor littlesnail. The snail was crawling on a one-meter rubber band at first, and it canmove on k cm every minute. But after that, the keeper stretches the rubber bandquickly, and it would be elongated one meter, during that the distances ratiobetween 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?”
Thesnail often asked himself such a question because he was afraid he would neversucceed. Now, we hope you can tell this poor snail when he would reach the endpoint.
Input
Everyline of the input contains an integer number k, indicating that the snail movedforward k cm every minute. (5 <= k <= 100)
Output
Outputan integer t, indicating that the snail doesn’t get to the endpoint until t-1minutes later, while t minutes later, it finally succeed.
SampleInput
10
100
SampleOutput
12367
1
题意:一根一米长的橡皮筋,蜗牛一分钟可以在上面爬行k米,它每爬行k米主人都会将橡皮筋拉长一米,但是蜗牛在橡皮筋上的相对位置不变,问蜗牛需要多长时间爬到橡皮筋终点。
解析:一道很简单的数学问题,可以计算出主人每次拉长橡皮筋后蜗牛距离重点的位置d,如果k>=d则下一分钟蜗牛就能到达终点。下面是AC代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
int k;
while(cin>>k)
{
if(k>=100) cout<<1<<endl;
else
{
double K=k*1.0;
double kk=k*1.0;
double x=100;
int i=0;
for(i=1;; i++)
{
x=100*i-kk;
x=(i+1)*1.0/i*(100*i-kk);
if(K>=x)
{
i++;
break;
}
kk=K+(i+1)*100-x;
}
cout<<i<<endl;
}
}
return 0;
}