POJ 1905 Expanding Rods

/*
Description
When a thin rod of length L is heated n degrees, it expands to a new length L'=(1+n*C)*L, where C is the coefficient of heat expansion. 
When a thin rod is mounted on two solid walls and then heated, it expands and takes the shape of a circular segment, the original rod being the chord of the segment. 


Your task is to compute the distance by which the center of the rod is displaced. 
Input
The input contains multiple lines. Each line of input contains three non-negative numbers: the initial lenth of the rod in millimeters, the temperature change in degrees and the coefficient of heat expansion of the material. Input data guarantee that no rod expands by more than one half of its original length. The last line of input contains three negative numbers and it should not be processed.
Output
For each line of input, output one line with the displacement of the center of the rod in millimeters with 3 digits of precision. 


  Sample Input
1000 100 0.0001
15000 10 0.00006
10 0 0.001
-1 -1 -1


  Sample Output
61.329
225.020
0.000
*******************************
这个解题报告都不想写了
水题2分
注意精度就行了
我因为那个
		if(n*c<=0)
		{
			printf("0.000\n");
			continue;
		}
		的特判...WA了10次...经验教训..经验教训
		WA的童鞋都注意点了,一个是精度,一个是特判,其他都没什么好注意的
*/


#include<stdio.h>
#include<math.h>
const double EPS = 1e-12;   //直接开到10^-12 0MS 飘过了...
const double PI = 3.1415926535897;
double f_abs(double x,double y)
{
	return x>y ? x-y : y-x;
}
int main()
{
//	freopen("in.txt","r",stdin);
	double l,n;
	double c; 
	while(~scanf("%lf%lf%lf",&l,&n,&c) && l != -1 && n != -1 && c != -1)
	{
		double L = (1+n*c)*l;
		double max = l/2 , min = 0,mid = (max+min)/2;
		if(n*c<=0)
		{
			printf("0.000\n");
			continue;
		}
		while(f_abs(max,min) > EPS) //我这里废话都多了点,心情不好随意吧
		{
			double a = PI - atan2(l/2,mid)*2;
			double x = l * a  / (2 * sin(a));
			if(x < L/2)
			{
				min = mid;
				mid = (max + min)/2;
			}
			else if(x > L/2)
			{
				max = mid;
				mid = (max + min)/2;
			}
			else if(x - L/2 < EPS)
				break;
		}
		printf("%.3lf\n",mid);
	}
	return 0;
}


posted @ 2012-03-14 21:06  Felix_F  阅读(159)  评论(0编辑  收藏  举报