POJ1905 Expanding Rods

来源:互联网 发布:小学作文解答软件 编辑:程序博客网 时间:2024/05/08 15:43
Problem 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.000115000 10 0.0000610 0 0.001-1 -1 -1

Sample Output
61.329225.0200.000
弧长公式:l=a*r(a是弧所对圆心角)假设半径r已知,用r和l/2表示出a,将求得的膨胀后的弧长与所给数值比较。
#include<stdio.h>#include<math.h>double c,t,n;int main(){double l,r,mid,p,q,L;while(scanf("%lf%lf%lf",&t,&n,&c)&&t>=0&&n>=0&&c>=0){L=(1+c*n)*t;l=0;r=t/2.0;while(r-l>1e-6){mid=(l+r)/2;p=(t*t/4+mid*mid)/(2*mid);q=2*p*asin(t/(2*p));if(L<q)r=mid;elsel=mid;}mid=(l+r)/2;printf("%.3f\n",mid);}return 0;}
0 0
原创粉丝点击