Open-air shopping malls
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1178 Accepted Submission(s): 412
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
lcy
题意:给你一些圆,要你求出以这些圆为圆心的一个大圆的最小半径,使得这个大圆覆盖所有圆至少一半的面积。。。
分析:解析几何的题吧,用到余弦定理,也就是求两圆相交的面积,高中的知识点,二分半径,然后判断即可
PS:高中知识退化导致我不会公式查了好久,然后自己写的不知道哪错了,最后看了别人的代码= =
今天这算神马状态啊,这种水题都wa好几次,还做这么就 T_T
代码:
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
typedef double diy;
struct circle
{
diy x,y,r;
}c[22];
int i,n,t;
diy l,r,m;
diy sqr(diy x){return x*x;}
diy Dis(circle a,circle b)
{
return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}
diy Angle(diy a,diy b,diy c)
{
return acos((b*b+c*c-a*a)/(2*b*c));
}
diy CircleInter(circle a,circle b)
{
diy d=Dis(a,b);
if(a.r+b.r<=d)return 0;
if(a.r<b.r)swap(a.r,b.r);
if(a.r-b.r>=d)return acos(-1.0)*b.r*b.r;
diy a1=Angle(b.r,a.r,d),a2=Angle(a.r,b.r,d);
return a1*a.r*a.r+a2*b.r*b.r-a.r*d*sin(a1);
}
bool ok()
{
int i,j;
diy tmp,s,a1,a2;
for(i=0;i<n;++i)
{
circle o=c[i];
o.r=m;
for(j=0;j<n;++j)
if(CircleInter(o,c[j])*2<acos(-1.0)*c[j].r*c[j].r)break;
if(j>=n)return 1;
}
return 0;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;++i)
scanf("%lf%lf%lf",&c[i].x,&c[i].y,&c[i].r);
l=0,r=1e6;
while(r-l>1e-6)
{
m=(l+r)/2;
if(ok())r=m;
else l=m;
}
printf("%.4lf\n",m);
}
return 0;
}