HDU 3264||POJ 3831 Open-air shopping malls【计算机几何】【圆相交面积模板】
来源:互联网 发布:网易云阅读 知乎 编辑:程序博客网 时间:2024/06/07 01:35
Open-air shopping malls
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 32768/32768 K (Java/Others)
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.
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.
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
120 0 12 0 1
Sample Output
2.0822
Hint
lcy
注意判断边界,枚举时要枚举每一个圆心
#include <bits/stdc++.h>#define ms(x,y) memset(x,y,sizeof(x))using namespace std;typedef long long ll;const double INF = 0x3f3f3f3f;const double eps = 1e-10;const double pi = acos(-1.0);const int mod = 1e9 + 7;const int maxn = 1e5 + 5;int n;int sgn(double x){if(fabs(x)<=eps)return 0;if(x>0) return 1;return -1;}struct Circle{double x,y,r;}a[55];double d2(Circle a,Circle b){return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}double s(Circle a,double k,Circle b){double r1=k,r2=b.r;double d=sqrt(d2(a,b));if(r1+r2<d+eps) return 0;if(d<fabs(r1-r2)+eps){double r=min(r1,r2);return pi*r*r;}double x=(d*d+r1*r1-r2*r2)/(2.0*d);double t1=acos(x/r1);double t2=acos((d-x)/r2);return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);}bool isok(Circle p,double r){bool ok=1;for(int i=0;i<n;i++){double s1=s(p,r,a[i]);double s2=pi*a[i].r*a[i].r-s1;// printf("%.10f %.10f\n", s1,s2);if(sgn(s2-s1)==1){ok=0;break;}}return ok;}double solve(Circle a,Circle b,double minv){double l=minv,r=minv+b.r,m=0;while(sgn(r-l)!=0){m=(l+r)/2.0;double s1=s(a,m,b);double s2=pi*b.r*b.r-s1;// printf("l = %.10f r = %.10f s1 = %.10f s2 = %.10f\n", l,r,s1,s2);if(isok(a,m)){r=m;}else l=m;}return m;}int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int t;scanf("%d",&t);while(t--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].r);}double ans=1000000000.0;if(n==1){printf("%.4f\n",a[0].r/sqrt(2));continue;}else{for(int i=0;i<n;i++){double temp=0;int k=-1;for(int j=0;j<n;j++){if (i==j)continue;double d=d2(a[i],a[j]);if(sgn(temp-d)==-1){temp=d;k=j;}}double res=solve(a[i],a[k],sqrt(temp));if(sgn(ans-res)==1){ans=res;}}}printf("%.4f\n", ans);}return 0;}
阅读全文
0 0
- HDU 3264||POJ 3831 Open-air shopping malls【计算机几何】【圆相交面积模板】
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
- hdu 3264 Open-air shopping malls 计算几何 相交圆的面积 二分
- HDU 3264 Open-air shopping malls [相交圆面积+二分查找]【计算几何】
- POJ 3831 & HDU 3264 Open-air shopping malls(几何)
- 计算几何 ( 求两圆相交面积 )——Open-air shopping malls ( HDU 3264 )
- 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 (两个圆的交面积+二分)
- poj 3831 Open-air shopping malls
- redis集群搭建(伪集群为例)
- WEB安全(占坑)
- 1000行代码读懂Spring(一)- 实现一个基本的IoC容器
- SELinux策略语言--类型强制(编写TE规则)
- 欢迎使用CSDN-markdown编辑器
- HDU 3264||POJ 3831 Open-air shopping malls【计算机几何】【圆相交面积模板】
- 玩CSS3动画(占坑)
- sublime 快捷键
- OneThink忘记密码 OneThink重置后台密码
- Synchronized 和Reentrantlock 的区别
- 用python做点儿事1 —— 基础
- 浅析Android下的Android.mk文件(一)
- linux系统下安装64位mysql 5.6的过程
- Unix-Linux编程实践教程——第十章