HDU 2832 Snail’s trouble(数学题)

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值