Open-air shopping malls(二分半径,两元交面积)
2015-07-30 10:07
411 查看
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
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
1
2
0 0 1
2 0 1
[align=left]Sample Output[/align]
2.0822
题意:给出很多的商店,要求一把打伞,伞的圆心要在某个商店中心,伞要覆盖每个圆至少一半的面积,求伞的最小半径
题解: 给的点一共20个,枚举不会超时,枚举每个圆心,然后二分半径找到最小的半径
下面是代码:
其中求两圆交面积的代码是复制的模板
#include <cstdio> #include <cmath> #include <algorithm> using namespace std; #define eps 1e-6 #define N 25 #define INF 20000 #define pi acos(-1.0) struct point{ double x, y; point(){} point(double _x, double _y) { x = _x, y = _y; } point operator - (point a){ return point(x-a.x, y-a.y); } double operator * (point a){ return x*a.y - y*a.x; } double len(){ return sqrt(x*x+y*y); } }; struct circle{ point c; double r; }; circle cir ; int n; double dist(point a, point b) { return (a-b).len(); } double area_cir_to_cir(circle a,circle b) { double d=dist(a.c,b.c),r1=a.r,r2=b.r,r; if (r1+r2<=d) { return 0.0; } else if (fabs(r1-r2)>=d) { r=min(r1,r2); return pi*r*r; } else { double a1=(r1*r1+d*d-r2*r2)/(2*r1*d); double a2=(r2*r2+d*d-r1*r1)/(2*r2*d); a1=2*acos(a1); a2=2*acos(a2); return (r1*r1*(a1-sin(a1))+r2*r2*(a2-sin(a2)))*0.5; } } bool check(circle a, circle b) { double s1 = area_cir_to_cir(a, b); double s2 = pi*b.r*b.r; return s1*2 > s2-eps; }//函数重载 bool check(point o, double r) { circle t; t.c = o, t.r = r; for(int i = 0; i < n; i++) if(!check(t, cir[i]))return false; return true; } double solve(int id) { point o = cir[id].c; double l = 0, r = INF; while(fabs(l-r) > eps) { double m = 0.5*(l+r); if(check(o, m)) r = m; else l = m; } return l; } int main() { int T; scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%lf %lf %lf", &cir[i].c.x, &cir[i].c.y, &cir[i].r); double ans = INF; for(int i = 0; i < n; i++) ans = min(ans, solve(i)); printf("%.4f\n", ans); } }
相关文章推荐
- 基于CLM(Constrained local model)人脸点检测算法
- Easy 2048 Again - ZOJ 3802 像缩进dp
- 怎么提高RailS应用的性能
- Rails项目中避免滥用这三种特性
- hdu 5319 Painter(杭电多校赛第三场)
- use sleep() to gain thread predictability
- HUAS Summer Trainning #3~B
- mongodb3.0.4 MongoDB-CR Authentication failed
- Everything Will Ultimately Fail
- 2015 Multi-University Training Contest 1
- hdoj 3420 bus Fair
- 1.2-对象的建立-main
- hdu 5316 Magician 2015 Multi-University Training Contest 3
- 本文大部分参考自 http://blog.csdn.net/mayingcai1987/article/details/6200909 ,对原文中的讲解FLAG_NEW_TASK地方加了一些自己的观点
- What does __init__ == __main__ mean?
- HDU_1789_DoingHomeworkAgain
- AIR 常用技巧
- aircrack-ng判断网卡是否兼容
- 2015 Multi-University Training Contest 3 1006 Beautiful Set
- K - After Training CodeForces 195B-找规律