poj 1905 Expanding Rods
Expanding Rods
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 9997 | Accepted: 2531 |
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.
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
Source
//这图形应该是个扇形d==(1+n*C)*L,d就是它的弧长,我们可以对半径r二分 //到时候根据勾股定理就可以求出h=sqrt(r*r-(l/2)*(l/2)); //现在推下弧长与半径的公式,d=r*2*α(α为弧度);sinα=(d/2)/r => // α=arcsin(d/(2*r)); ==>d=r*2*arcsin(d/(2*r)); #include<stdio.h> #include<math.h> int main() { double l,n,c,d,left,r,mid; while(scanf("%lf %lf %lf",&l,&n,&c)!=EOF) { d=(1+n*c)*l; if(l==-1&&n==-1&&c==-1) break; if(d==l) { printf("0.000\n"); continue; } left=0.0,r=999999999; while(r-left>1e-6)//精度不要太大,不然会超时 { mid=(left+r)/2; if(2*mid*asin(l/(2*mid))<d)//弧长比目标弧长小,半径就要变小,自己画个图就出来了 r=mid; else left=mid; } printf("%.3lf\n",mid-sqrt(mid*mid-(l/2)*(l/2))); } return 0; }