HDU 3264 Open-air shopping malls(两圆相交公共部分面积 二分答案)
2013-07-27 18:33
429 查看
Open-air shopping malls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1427 Accepted Submission(s): 500
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
2009 Asia Ningbo Regional Contest Hosted by NIT
Recommend
lcy
这个题目比较有意思
这个题目两个圆相交公式是参考这篇博客:http://blog.sina.com.cn/s/blog_850498e20100w6fq.html
对于这个题目个人感觉比较有意思,也比较好想,首先看这个题目的数据量比较小,肯定枚举能搞定
然后想求出答案,貌似不好直接求出答案,这时候想到二分枚举答案,不过精度要控好
这个题目不要想当然的认为离当前圆心最远的点就是答案的出现点,只要在那个圆上枚举就可以了,这个想法
是错误的,假设这个圆半径很小呢,那么枚举出来的结果可能就是错误的!
#include <iostream> #include <string.h> #include <stdio.h> #include <cmath> using namespace std; #define eps 1e-8 #define pi acos(-1.0) struct point { double x; double y; double r; double area; }po[200]; int n; double global_ans; double map[50][50]; double area(point a,double r1,point b,double r2) { double d=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));//圆心距 if(r1>r2) { double temp=r1; r1=r2; r2=temp; }//r1取小 if(r1+r2<=d) return 0;//相离 else if(r2-r1>=d) return pi*r1*r1;//内含 else { double a1=acos((r1*r1+d*d-r2*r2)/(2.0*r1*d)); double a2=acos((r2*r2+d*d-r1*r1)/(2.0*r2*d)); return (a1*r1*r1+a2*r2*r2-r1*d*sin(a1)); }//相交 } double dis(point &a,point &b) { return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y*b.y)); } double find_ans(int num,double left,double right) { double temp,mid; if(right > global_ans) right=global_ans; int i; while(right - left > eps) { mid=(right+left)/2; for(i=0;i<n;i++) { temp=area(po[num],mid,po[i],po[i].r); if(temp < po[i].area/2) { left=mid;break;} } if(i==n) right=mid; } if(global_ans > (left+right)/2) global_ans=(left+right)/2; return 0; } int main() { int t; int i,j; scanf("%d",&t); double MAX; while(t--) { scanf("%d",&n); MAX=-1; for(i=0;i<n;i++) { scanf("%lf%lf%lf",&po[i].x,&po[i].y,&po[i].r); po[i].area=pi*po[i].r*po[i].r; } if(n==1) { printf("%.4lf\n",po[0].r/sqrt(2.0)); ////////////////////////////////////// continue; } for(i=0;i<n;i++) for(j=i;j<n;j++) map[i][j]=map[j][i]=dis(po[i],po[j]); global_ans=1e8; for(i=0;i<n;i++) find_ans(i,0,1e6); printf("%.4lf\n",global_ans); } return 0; }
相关文章推荐
- [hdu 3264] Open-air shopping malls(二分+两圆相交面积)
- hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1
- HDU 3264 Open-air shopping malls [相交圆面积+二分查找]【计算几何】
- HDU 3264 Open-air shopping malls(圆相交面积+二分)
- hdu 3264 Open-air shopping malls(圆相交面积+二分)
- [hdu 3264] Open-air shopping malls(二分+两圆相交面积)
- hdu 3264 Open-air shopping malls(二分+两圆相交面积)
- HDU 3264 Open-air shopping malls (计算两圆相交的面积 + 二分)
- hdu 3264 Open-air shopping malls(求圆相交的面积,二分)
- hdu 3264 Open-air shopping malls 计算几何 相交圆的面积 二分
- HDU 3264 Open-air shopping malls(圆的面积交+二分)
- HDU 3264 Open-air shopping malls (两个圆的交面积+二分)
- hdu - 3264 - Open-air shopping malls(二分 + 圆面积交)
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
- HDU 3264||POJ 3831 Open-air shopping malls【计算机几何】【圆相交面积模板】
- 计算几何 ( 求两圆相交面积 )——Open-air shopping malls ( HDU 3264 )
- hdu 3264 Open-air shopping malls 求两圆相交
- HDU 3264/POJ 3831 Open-air shopping malls(计算几何+二分)(2009 Asia Ningbo Regional)
- HDU 3264 Open-air shopping malls(二分查找)
- Open-air shopping malls 两圆面积相交,二分搜索半径