标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2256 Accepted Submission(s): 837
1 /************************************************************************* 2 > File Name: code/hdu/3264.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年11月06日 星期五 14时57分47秒 6 ************************************************************************/ 7 8 #include<iostream> 9 #include<iomanip> 10 #include<cstdio> 11 #include<algorithm> 12 #include<cmath> 13 #include<cstring> 14 #include<string> 15 #include<map> 16 #include<set> 17 #include<queue> 18 #include<vector> 19 #include<stack> 20 #include<cctype> 21 #define fst first 22 #define sec second 23 #define lson l,m,rt<<1 24 #define rson m+1,r,rt<<1|1 25 #define ms(a,x) memset(a,x,sizeof(a)) 26 using namespace std; 27 const double eps = 1E-8; 28 const int dx4[4]={1,0,0,-1}; 29 const int dy4[4]={0,-1,1,0}; 30 typedef long long LL; 31 const int inf = 0x3f3f3f3f; 32 const int N=25; 33 const double pi =acos(-1.0); 34 int n; 35 int dblcmp(double d) 36 { 37 return d<-eps?-1:d>eps; 38 } 39 struct point 40 { 41 double x,y; 42 point(){} 43 point(double _x,double _y): 44 x(_x),y(-y){}; 45 void input() 46 { 47 scanf("%lf%lf",&x,&y); 48 } 49 point sub(point p) 50 { 51 return point(x-p.x,y-p.y); 52 } 53 double dot(point p) 54 { 55 return x*p.x+y*p.y; 56 } 57 double det(point p) 58 { 59 return x*p.y-y*p.x; 60 } 61 double distance(point p) 62 { 63 return hypot(x-p.x,y-p.y); 64 } 65 }; 66 67 struct circle 68 { 69 point p; 70 double r; 71 circle(){} 72 circle(point _p,double _r): 73 p(_p),r(_r){}; 74 void input() 75 { 76 p.input(); 77 scanf("%lf",&r); 78 } 79 double area() 80 { 81 return pi*r*r; 82 } 83 84 int relationcircle(circle v) 85 { 86 double d=p.distance(v.p); 87 if (dblcmp(d-r-v.r)>0) return 5; 88 if (dblcmp(d-r-v.r)==0) return 4; 89 double l = fabs(r-v.r); 90 if (dblcmp(d-r-v.r)<0&&dblcmp(d-l)>0) return 3; 91 if (dblcmp(d-l)==0) return 2; 92 if (dblcmp(d-l)<0) return 1; 93 } 94 95 double areacircle(circle v) 96 { 97 int rel = relationcircle(v); 98 if (rel>=4) return 0.0; 99 if (rel<=2) return min(area(),v.area()); 100 double d=p.distance(v.p); 101 double hf=(r+v.r+d)/2.0; 102 double ss=2*sqrt(hf*(hf-r)*(hf-v.r)*(hf-d)); 103 double a1=acos((r*r+d*d-v.r*v.r)/(2.0*r*d)); 104 a1 = a1 *r*r; 105 double a2=acos((v.r*v.r+d*d-r*r)/(2.0*v.r*d)); 106 a2 = a2*v.r*v.r; 107 return a1+a2-ss; 108 } 109 }cir[N]; 110 111 bool judge(double rr) 112 { 113 for ( int i = 1 ,j; i <= n ; i++) 114 { 115 circle tmp = cir[i]; 116 tmp.r = rr; 117 for ( j = 1; j <= n ; j++) 118 { 119 double crossarea = tmp.areacircle(cir[j]); 120 // cout<<"cross_area:"<<crossarea<<endl; 121 if (crossarea<cir[j].area()/2.0) 122 break; 123 } 124 if (j==n+1) return true; 125 126 } 127 return false; 128 129 } 130 int main() 131 { 132 #ifndef ONLINE_JUDGE 133 freopen("in.txt","r",stdin); 134 #endif 135 int T; 136 scanf("%d",&T); 137 while ( T-- ) 138 { 139 scanf("%d",&n); 140 for ( int i = 1 ; i <= n ; i++) cir[i].input(); 141 double l=0,r=1E5; 142 while (dblcmp(r-l)>0) 143 { 144 // cout<<"l:"<<l<<" r:"<<r<<endl; 145 double mid = (l+r)/2.0; 146 if (judge(mid)) 147 r = mid; 148 else l=mid; 149 150 } 151 printf("%.4f\n",r); 152 153 } 154 155 156 #ifndef ONLINE_JUDGE 157 #endif 158 fclose(stdin); 159 return 0; 160 }
hdu 3264 Open-air shopping malls(求圆相交的面积,二分)
标签:
原文地址:http://www.cnblogs.com/111qqz/p/4942802.html