A - Expanding Rods
Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice POJ
1905
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
/* Author: 2486 Memory: 164 KB Time: 0 MS Language: C++ Result: Accepted */ //从边的角度思考 #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const double PI=3.1415926535898; const double eps=1e-7; double iL,t,c,Ls; bool C(double m){ double r=m+iL*iL/(4.0*m); return asin(iL/r)*r>=Ls; } int main(){ while(~scanf("%lf%lf%lf",&iL,&t,&c)){ if(iL<0||t<0||c<0)break; Ls=(1.0+t*c)*iL; double lb=0,ub=iL/2.0; while(ub-lb>eps){ double mid=(ub+lb)/2.0; if(C(mid)){ ub=mid; } else lb=mid; } printf("%.3lf\n",ub); } return 0; }
以上的是通过相似三角形的思维,m/(L/2)=(L/2)/(2R-m)
一下是通过角度a=L/R,所对应的角
/* Author: 2486 Memory: 176 KB Time: 0 MS Language: C++ Result: Accepted */ #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> //从角的角度思考 using namespace std; const double PI=acos(-1.0); const double eps=1e-15; double iL,t,c,Ls; bool C(double m){ if(((iL/sin(m))/2)*m*2.0>=Ls)return true; return false; } int main(){ while(~scanf("%lf%lf%lf",&iL,&t,&c)){ if(iL<0||t<0||c<0)break; Ls=(1.0+t*c)*iL; double lb=0,ub=PI/2.0; while(ub-lb>eps){ double mid=(ub+lb)/2.0; if(C(mid)){ ub=mid; } else lb=mid; } printf("%.3lf\n",(iL/2/sin(ub))-iL/2/tan(ub)); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。