标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1822 Accepted Submission(s): 651
题目大意:给n个圆,求以某个圆的圆心为圆心作圆它与所有圆的交都大于等于圆面积一半的最小半径。
思路:枚举圆心二分找答案。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 7 const double eps=1e-8; 8 const double Pi=acos(-1.0); 9 struct Point 10 { 11 double x,y; 12 Point(double x=0,double y=0):x(x),y(y) {} 13 }; 14 typedef Point Vector; 15 Vector operator +(Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);} 16 Vector operator -(Vector A,Vector B){return Vector(A.x-B.x,A.y-B.y);} 17 Vector operator *(Vector A,double p){return Vector(A.x*p,A.y*p);} 18 Vector operator /(Vector A,double p){return Vector(A.x/p,A.y/p);} 19 double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}//点积 20 double Length(Vector A){return sqrt(Dot(A,A));}//向量的长度 21 inline double min(double a,double b){return a>b?b:a;} 22 const int maxn=30; 23 int n; 24 struct circle 25 { 26 Point c; 27 double r; 28 }C[maxn]; 29 30 double getarea(int id,int i,double r) 31 { 32 double clen=Length(C[id].c-C[i].c); 33 if(clen>=r+C[i].r) return 0; 34 double t=min(r,C[i].r); 35 if(clen<=fabs(r-C[i].r)) return Pi*t*t; 36 double ang1=acos((r*r+clen*clen-C[i].r*C[i].r)/(2*r*clen)); 37 double ang2=acos((C[i].r*C[i].r+clen*clen-r*r)/(2*C[i].r*clen)); 38 double area=ang1*r*r+ang2*C[i].r*C[i].r; 39 area-=sin(ang2)*C[i].r*clen; 40 return area; 41 } 42 43 bool judge(int id,double r) 44 { 45 for(int i=0;i<n;i++) 46 { 47 double area=getarea(id,i,r); 48 if(Pi*C[i].r*C[i].r>2*area) 49 return false; 50 } 51 return true; 52 } 53 54 double binary_search(double l,double r,int id) 55 { 56 double mid; 57 while(r-l>eps) 58 { 59 mid=(l+r)/2.0; 60 if(judge(id,mid)) r=mid; 61 else l=mid; 62 } 63 return l; 64 } 65 66 void solve() 67 { 68 double ans=50000; 69 for(int i=0;i<n;i++) 70 ans=min(ans,binary_search(0,40000,i)); 71 printf("%.4lf\n",ans); 72 } 73 int main() 74 { 75 int i,t; 76 scanf("%d",&t); 77 while(t--) 78 { 79 scanf("%d",&n); 80 for(i=0;i<n;i++) 81 scanf("%lf%lf%lf",&C[i].c.x,&C[i].c.y,&C[i].r); 82 solve(); 83 } 84 return 0; 85 }
hdu 3264 圆的交+二分,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/xiong-/p/3923542.html