Open-air shopping malls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2682 Accepted Submission(s): 1015
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.
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
1 2 0 0 1 2 0 1
Sample Output
2.0822
Source
Recommend
题意:给n个圆的坐标和半径,在某一个圆心做半径为r的圆,使这个圆能覆盖所有圆至少一半的面积,求最小的r
直接暴力枚举,从某一个点二分求出符合要求的半径值r,求出最小r即可
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
#define pi acos(-1.0)
#define eps 1e-8
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))
const double inf=0x3f3f3f3f;
int t,m;
struct Cir
{
double x,y,r;
Cir(double x=0,double y=0,double r=0):x(x),y(y),r(r){}
}C[10000];
double len(const Cir& a,const Cir& b)
{
return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
double area(const Cir& a,const Cir& b)//计算两个圆重合的面积
{
double l=len(a,b);
if(l>=a.r+b.r)return 0;
if(l<=fabs(a.r-b.r))
return pi*pow(min(a.r,b.r),2);
double c=acos((a.r*a.r+l*l-b.r*b.r)/2/a.r/l);
double d=acos((b.r*b.r+l*l-a.r*a.r)/2/b.r/l);
return c*a.r*a.r+d*b.r*b.r-a.r*l*sin(c);
}
bool check(const Cir& a)//判断当前半径是否满足条件
{
for1(i,m)
if(area(a,C[i])<pi*C[i].r*C[i].r/2)return 0;
return 1;
}
int main()
{
sf("%d",&t);
while(t--)
{
double q=1e10;
sf("%d",&m);
for1(i,m)
sf("%lf%lf%lf",&C[i].x,&C[i].y,&C[i].r);
for1(i,m)
{
double p=0.0;
for(int j=1;j<=m;j++)
p=max(p,len(C[i],C[j])+C[j].r);//可能半径到的最大值为这个点到其他的点的距离加上半径
double l=0,r=p;
double mid;
while(fabs(l-r)>=eps)//二分求满足条件每组圆的最小半径
{
mid=(l+r)/2.0;
Cir y(C[i].x,C[i].y,mid);
if(check(y))
r=mid;
else
l=mid+eps;
}
q=min(q,mid);
}
pf("%.4f\n",q);
}
return 0;
}