三分
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define rep(i,a,b) for(int i=a;i<=b;++i) 4 #define ms(arr,a) memset(arr,a,sizeof arr) 5 const double eps=1e-14; 6 const int maxn=1e5+5; 7 int N; 8 double r[maxn]; 9 double calc(double o) 10 { 11 double odd=min(1.0-o,o),even=max(1.0-o,o); 12 double R=even*even+r[N]; 13 rep(i,1,N-1) 14 { 15 if(i&1) 16 { 17 odd++; 18 R=max(R,odd*odd+r[N-i]); 19 } 20 else 21 { 22 even++; 23 R=max(R,even*even+r[N-i]); 24 } 25 } 26 return sqrt(R); 27 } 28 double solve(double l,double r) 29 { 30 double mid,mmid; 31 while(l<r) 32 { 33 mid=(l+r)/2.0; 34 mmid=(mid+r)/2.0; 35 if(calc(mmid)<calc(mid)) 36 l=mid+eps; 37 else r=mmid-eps; 38 } 39 return calc(l); 40 } 41 int main() 42 { 43 int T; 44 scanf("%d",&T); 45 for(int Case=1;Case<=T;Case++) 46 { 47 scanf("%d",&N); 48 rep(i,1,N) 49 { 50 double a,b; 51 scanf("%lf%lf",&a,&b); 52 double Max,Min; 53 Max=max(a,b); 54 Min=min(a,b); 55 r[i]=(Max/2.0)*(Max/2.0)+Min*Min; 56 } 57 sort(r+1,r+N+1); 58 printf("Case #%d: %.10f ",Case,solve(0,1)); 59 } 60 }