poj1905

Expanding Rods
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 10901   Accepted: 2802

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



思路:采用对半径进行二分的思想


 1 #include
 2 #include
 3 #include<string.h>
 4 #include
 5 #define M 0xfffffff
 6 using namespace std;
 7 int main()
 8 {
 9     double n,L,L1,c;
10     while(scanf("%lf%lf%lf",&L,&n,&c)!=EOF)
11     {
12         if(L<0)
13         break;
14         if(n*c<0.000001)//此种情况不能构成圆形
15         {
16             printf("0.000\n");
17             continue;
18         }
19         L1=(1+n*c)*L;
20         double low=0,high=M,mid;
21         while(high-low>0.000001)
22         {
23             mid=(high+low)/2;
24             double angle=asin(0.5*L/mid);
25             if(2*angle*mid<L1)
26             high=mid;
27             else
28             low=mid;
29         }
30         printf("%.3lf\n",mid-sqrt(mid*mid-0.5*L*0.5*L));
31     }
32     return 0;
33 }
View Code

 

转载于:https://www.cnblogs.com/lxm940130740/p/3642427.html

你可能感兴趣的:(poj1905)