标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2139 Accepted Submission(s): 775
题意:给出很多的商店,要求一把打伞,伞的圆心要在某个商店中心,伞要覆盖每个圆至少一半的面积,求伞的最小半径
题解: 给的点一共20个,枚举不会超时,枚举每个圆心,然后二分半径找到最小的半径
下面是代码:
其中求两圆交面积的代码是复制的模板
1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 using namespace std; 5 #define eps 1e-6 6 #define N 25 7 #define INF 20000 8 #define pi acos(-1.0) 9 struct point{ 10 double x, y; 11 point(){} 12 point(double _x, double _y) { 13 x = _x, y = _y; 14 } 15 16 point operator - (point a){ 17 return point(x-a.x, y-a.y); 18 } 19 20 double operator * (point a){ 21 return x*a.y - y*a.x; 22 } 23 24 double len(){ 25 return sqrt(x*x+y*y); 26 } 27 }; 28 struct circle{ 29 point c; 30 double r; 31 }; 32 circle cir[N]; 33 int n; 34 35 double dist(point a, point b) 36 { 37 return (a-b).len(); 38 } 39 40 double area_cir_to_cir(circle a,circle b) 41 { 42 double d=dist(a.c,b.c),r1=a.r,r2=b.r,r; 43 if (r1+r2<=d) { return 0.0; } 44 else if (fabs(r1-r2)>=d) { 45 r=min(r1,r2); 46 return pi*r*r; 47 } 48 else { 49 double a1=(r1*r1+d*d-r2*r2)/(2*r1*d); 50 double a2=(r2*r2+d*d-r1*r1)/(2*r2*d); 51 a1=2*acos(a1); a2=2*acos(a2); 52 return (r1*r1*(a1-sin(a1))+r2*r2*(a2-sin(a2)))*0.5; 53 } 54 } 55 56 bool check(circle a, circle b) 57 { 58 double s1 = area_cir_to_cir(a, b); 59 double s2 = pi*b.r*b.r; 60 return s1*2 > s2-eps; 61 }//函数重载 62 63 bool check(point o, double r) 64 { 65 circle t; 66 t.c = o, t.r = r; 67 for(int i = 0; i < n; i++) 68 if(!check(t, cir[i]))return false; 69 return true; 70 } 71 72 double solve(int id) 73 { 74 point o = cir[id].c; 75 double l = 0, r = INF; 76 while(fabs(l-r) > eps) 77 { 78 double m = 0.5*(l+r); 79 if(check(o, m)) r = m; 80 else l = m; 81 } 82 return l; 83 } 84 85 int main() 86 { 87 int T; 88 scanf("%d", &T); 89 while(T--) 90 { 91 scanf("%d", &n); 92 for(int i = 0; i < n; i++) 93 scanf("%lf %lf %lf", &cir[i].c.x, &cir[i].c.y, &cir[i].r); 94 double ans = INF; 95 for(int i = 0; i < n; i++) 96 ans = min(ans, solve(i)); 97 printf("%.4f\n", ans); 98 } 99 }
Open-air shopping malls(二分半径,两元交面积)
标签:
原文地址:http://www.cnblogs.com/shanyr/p/4688354.html