poj 1905 Expanding Rods(二分)

题目:http://poj.org/problem?id=1905

题意:看图就明白了。。。

杆原长为L,受热膨胀弯曲后的长度为 L'=(1+n*C)*L,求中心的移动的距离h;

思路:推出两个公式:s为弧长

对h进行二分,得出r,代入(2)式,与s进行大小比较

代码:

View Code
 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std;
 5 const double esp=1e-5;   //最低精度限制
 6 int main()
 7 {
 8     double L,n,C;
 9     while(scanf("%lf%lf%lf",&L,&n,&C)!=EOF)
10     {
11         if(L<0&&n<0&&C<0)
12         break;
13         double LL;
14         LL=(1+n*C)*L;
15         double low,high;
16         double R,mid;
17         low=0;
18         high=L/2;
19         while(high-low>esp)
20         {
21             mid=(high+low)/2;
22             R=((mid*mid*4)+(L*L))/(8*mid);
23             if((2*R*asin(L/(2*R)))<LL)
24             low=mid;
25             else
26             high=mid;
27         }
28         printf("%.3f\n",mid);
29     }
30     return 0;
31 }

 

posted @ 2013-02-21 13:20  琳&leen  阅读(248)  评论(0编辑  收藏  举报