Open-air shopping malls(二分半径,两元交面积)

http://acm.hdu.edu.cn/showproblem.php?pid=3264

Open-air shopping malls

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

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

题意:给出很多的商店,要求一把打伞,伞的圆心要在某个商店中心,伞要覆盖每个圆至少一半的面积,求伞的最小半径

题解: 给的点一共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 }
时间: 2024-11-10 00:10:49

Open-air shopping malls(二分半径,两元交面积)的相关文章

hdu3264Open-air shopping malls(二分)

链接 枚举伞的圆心,最多只有20个,因为必须与某个现有的圆心重合. 然后再二分半径就可以了. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9

hdu 3264 Open-air shopping malls(求圆相交的面积,二分)

Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2256    Accepted Submission(s): 837 Problem Description The city of M is a famous shopping city and its open-air shopping

HDU 3264 Open-air shopping malls (两个圆的交面积+二分)

题目链接 :HDU 3264 Open-air shopping malls 题意:给出n个圆.要求一个在n个圆的圆心建一个大圆,使大圆与每一个小圆的交面积大于等于该小圆的面积的一般.求最小的大圆半径. 思路:二分大圆半径,枚举每个小圆与大圆的交面积. 注意精度问题. AC代码: #include <stdio.h> #include <math.h> #include <algorithm> const double eps=1e-6; const double PI

hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分

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

HDU 3264 Open-air shopping malls(圆相交面积+二分)

HDU 3264 Open-air shopping malls(圆相交面积+二分) ACM 题目地址:HDU 3264 Open-air shopping malls 题意: 给出一些圆,选择其中一个圆的圆心为圆心,然后画一个大圆,要求大圆最少覆盖每个圆的一半面积.求最小面积. 分析: 枚举每个点,用二分求出需要的圆,更新最小值即可. 其中用到了圆相交面积,可以参考这题: POJ 2546 Circular Area(两个圆相交面积) 代码: /* * Author: illuz <iillu

hdu 3264 Open-air shopping malls 求两圆相交

对每个圆二分半径寻找可行的最小半径,然后取最小的一个半径. 对于两圆相交就只要求到两个扇形,然后减去两个全等三角形就行了. #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> using namespace std; #define pi acos(-1.0) #define eps 1e-8 #define maxn 50 int n; struct point{

POJ 3831 &amp; HDU 3264 Open-air shopping malls(几何)

题目链接: POJ:http://poj.org/problem?id=3831 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3264 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

Intersection(HDU5120 + 圆交面积)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5120 题目: 题意: 求两个圆环相交的面积. 思路: 两个大圆面积交-2×大圆与小圆面积交+两小圆面积交. 代码实现如下: 1 #include <set> 2 #include <map> 3 #include <deque> 4 #include <ctime> 5 #include <stack> 6 #include <cmath&g

HDU3264 Open-air shopping malls (圆交+二分)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意: 给定n个圆的圆心和半径,求一个圆心为这些圆中任意一个,与所有圆相交的面积超过其面积一半的圆的最小半径. 分析: 枚举圆心,然后二分得到最小的半径,直接套求圆交的模板. 代码如下: #include <iostream> #include <cstring> #include <cstdio> #include <cmath> using name