zoj 2370 || poj 1905 Expanding Rods

这题木有想到好方法,看poj discuss,用的是二分。

 

然后就想二分角度,结果,精度开到了12才过。。。T T。。。然后看题解,只有二分长度的,精度比较低。

 

#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <algorithm> using namespace std; const double pi = acos(-1.0); const double eps = 1e-12; bool dy(double x,double y) { return x > y + eps;} // x > y bool xy(double x,double y) { return x < y - eps;} // x < y bool dyd(double x,double y) { return x > y - eps;} // x >= y bool xyd(double x,double y) { return x < y + eps;} // x <= y bool dd(double x,double y) { return fabs( x - y ) < eps;} // x == y double r,a; double n,c,l,L; void bsearch() { double beg = 0.0,end = pi; while( xy(beg,end) ) { double mid = (beg+end)/2; a = mid; r = L/mid; if( dy(2*L*sin(a/2),l*mid) ) beg = mid; else end = mid; } } int main() { while( ~scanf("%lf%lf%lf",&l,&n,&c) ) { if( l == n && l == c && c == -1 ) break; if( dd(l,0.0) || dd(n,0.0) || dd(c,0.0) ) { printf("0.000/n"); continue; } L = (1+n*c)*l; bsearch(); double ans = L/a - (L*cos(a/2)/a); printf("%.3lf/n",ans); } return 0; }  

你可能感兴趣的:(c)