HDU 3264 Open-air shopping malls

来源:互联网 发布:js 事件绑定区别 编辑:程序博客网 时间:2024/05/16 11:35


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
120 0 12 0 1
 

Sample Output
2.0822
 

Source
2009 Asia Ningbo Regional Contest Hosted by NIT
 

Recommend
lcy   |   We have carefully selected several similar problems for you:  3265 3269 3263 3260 3261 

 


第一眼就是2分,枚举每一个圆的圆心,然后判断一下right的最大距离。

对于每一个圆心,枚举其他的圆心,判断相交的是否大于每个圆的面积的一半。

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;typedef long long ll;const int N = 21;const double PI = acos(-1.0);const double EPS = 1e-8;int t, n;struct Round{    double x, y;    double r;} r[N], node;double dis(const Round &a, const Round &b){    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}double check1(Round &a, Round &b){    double d = dis(a, b);    if (d >= a.r + b.r)        return 0;    if (d <= fabs(a.r - b.r))    {        double r = a.r < b.r ? a.r : b.r;        return PI * r * r;    }    double ang1 = acos((a.r * a.r + d * d - b.r * b.r) / 2. / a.r / d);    double ang2 = acos((b.r * b.r + d * d - a.r * a.r) / 2. / b.r / d);    double ret = ang1 * a.r * a.r + ang2 * b.r * b.r - d * a.r * sin(ang1);    return ret;}bool check(Round& node){    for(int i=0; i<=n-1; i++)    {        if (check1(node, r[i]) * 2 < PI * r[i].r * r[i].r)            return false;    }    return true;};double bin(double l, double r, Round& node){    double mid;    while (fabs(l - r) >= EPS)    {        mid = (l + r) / 2;        node.r = mid;        if (check(node))        {            r = mid;        }        else        {            l = mid + EPS;        }    }    return mid;}int main(){    scanf("%d", &t);    while (t--)    {        scanf("%d", &n);        for(int i=0; i<=n-1; i++)            scanf("%lf%lf%lf", &r[i].x, &r[i].y, &r[i].r);        double ans = 1e9+10005;        for(int i=0; i<=n-1; i++)        {            node.x = r[i].x;            node.y = r[i].y;            double right = 0;            for(int j=0; j<=n-1; j++)                right = max(right, dis(node, r[j]) + r[j].r);            ans = min(ans, bin(0, right, node));        }        printf("%.4f\n", ans);    }    return 0;}


0 0