现在的位置: 首页 > 综合 > 正文

杭电 2832 水题

2013年10月17日 ⁄ 综合 ⁄ 共 1470字 ⁄ 字号 评论关闭

        此题应该是有公式的,可惜吾等弱菜实在太弱,程序愣是跑了9500ms才过,,,惭愧。看着别人0msAC的,无颜面对啊。。。题目:

Snail’s trouble

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 416    Accepted Submission(s): 226


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
 

ac代码:

#include <iostream>
#include <cstdio>
using namespace std;
double ee=1e-8;
int main(){
  //freopen("1.txt","r",stdin);
  int k;
  while(~scanf("%d",&k)){
    _int64 count=1,len=0,stick=100;
	double leftside=k*1.0;
	double rightside=100;
	double ss;
	while((stick*1.0)-leftside>ee){
	  rightside=stick-leftside;
	  stick+=100;
	  leftside=((stick*1.0)/(stick-100))*leftside+k*1.0;
	  count++;
	}
	printf("%I64d\n",count);
  }
  return 0;
}

抱歉!评论已关闭.