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. That means you have to calculate h as in the picture.
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case contains three non-negative real numbers: the initial length of the rod in millimeters L, the temperature change in degrees n and the coefficient of heat expansion of the material C. Input data guarantee that no rod expands by more than one half of its original length. All the numbers will be between 0 and 1000 and there can be at most 5 digits after the decimal point.
Output
For each case, print the case number and the displacement of the center of the rod in single line. Errors less than 10-6 will be ignored.
Sample Input
3
1000 100 0.0001
150 10 0.00006
10 0 0.001
Sample Output
Case 1: 61.3289915
Case 2: 2.2502024857
Case 3: 0
1 #include<cstdio> 2 #include<algorithm> 3 #include<cmath> 4 #include<iostream> 5 using namespace std; 6 #define eps 1e-8 7 #define PI acos(-1.0) 8 int main() 9 { 10 int t,i; 11 cin>>t; 12 for(i = 1;i <= t;i++) 13 { 14 double l,n,c; 15 cin>>l>>n>>c; 16 double low = 0,right = l*0.5,mid; 17 double s = (1+n*c)*l; 18 while(right-low>eps) 19 { 20 mid = (low+right)/2; 21 int r; 22 r = (4*mid*mid+l*l)/(8*mid); 23 int x = 2*r*asin(l/(2*r)); 24 if(2*r*asin(l/(2*r))<s) 25 low = mid; 26 else 27 right = mid; 28 } 29 printf("Case %d: %.7lf\n",i,right); 30 } 31 return 0; 32 } 33 //关于asin的增减性是个问题!! right不要太大!