码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 3264 圆的交+二分

时间:2014-08-19 23:53:45      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   java   os   io   

Open-air shopping malls

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1822    Accepted Submission(s): 651


Problem Description
The city of M is a famous shopping city and its open-air shopping malls are extremely attractive. During the tourist seasons, thousands of people crowded into these shopping malls and enjoy the vary-different shopping.

Unfortunately, the climate has changed little by little and now rainy days seriously affected the operation of open-air shopping malls—it’s obvious that nobody will have a good mood when shopping in the rain. In order to change this situation, the manager of these open-air shopping malls would like to build a giant umbrella to solve this problem. 

These shopping malls can be considered as different circles. It is guaranteed that these circles will not intersect with each other and no circles will be contained in another one. The giant umbrella is also a circle. Due to some technical reasons, the center of the umbrella must coincide with the center of a shopping mall. Furthermore, a fine survey shows that for any mall, covering half of its area is enough for people to seek shelter from the rain, so the task is to decide the minimum radius of the giant umbrella so that for every shopping mall, the umbrella can cover at least half area of the mall.
 

 

Input
The input consists of multiple test cases. 
The first line of the input contains one integer T (1<=T<=10), which is the number of test cases.
For each test case, there is one integer N (1<=N<=20) in the first line, representing the number of shopping malls.
The following N lines each contain three integers X,Y,R, representing that the mall has a shape of a circle with radius R and its center is positioned at (X,Y). X and Y are in the range of [-10000,10000] and R is a positive integer less than 2000.
 

 

Output
For each test case, output one line contains a real number rounded to 4 decimal places, representing the minimum radius of the giant umbrella that meets the demands.
 

 

Sample Input
1 2 0 0 1 2 0 1
 

 

Sample Output
2.0822
 

 

Source
 

题目大意:给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

hdu 3264 圆的交+二分

标签:des   style   blog   http   color   java   os   io   

原文地址:http://www.cnblogs.com/xiong-/p/3923542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!