poj 1905 Expanding Rods

由题知道所求的值0<=x<l/2;所以用二分就可以很快的解决!!!

代码如下:

 

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<algorithm>
 4 #include<iomanip>
 5 #include<cmath>
 6 #include<cstring>
 7 #include<vector>
 8 //#define ll __int64
 9 #define pi acos(-1.0)
10 #define MAX 50000
11 using namespace std;
12 int main(){
13     int n,m,i,sum;
14     double l2,c,l,ll,rr,r,mid,s;
15     while(cin>>l>>n>>c){
16         if (l<0&&n<0&&c<0) break;
17         l2 = (1+c*n)*l;
18         ll=0,rr=l/2;
19         while(rr-ll>1e-8){
20             mid = (ll+rr)/2;
21             r = mid/2+l*l/(8*mid);
22             s = 2*r*asin(l/(2*r));
23             if (fabs(l2-s)<=1e-8)
24                 break;
25             else if (l2>s) ll = mid;
26             else rr = mid;
27         }
28         printf("%.3lf\n",mid);
29     }
30     return 0;
31 }
View Code

 

 

 

 

 

 

posted @ 2013-07-30 12:30  _随心所欲_  阅读(139)  评论(0编辑  收藏  举报