POJ 3831 & HDU 3264 Open-air shopping malls(几何)

简介:

题目链接:

POJ:http://poj.org/problem?id=3831

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=3264


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


题意: 
给出一些圆,选择当中一个圆的圆心为圆心。然后画一个大圆。要求大圆最少覆盖每一个圆的一半面积。求最小面积。

代码例如以下:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>


using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0);

int sgn(double x)
{
    if(fabs(x) < eps) return 0;
    if(x < 0) return - 1;
    else return 1;
}
struct Point
{
    double x, y, r;
    Point() {}
    Point(double _x, double _y)
    {
        x = _x;
        y = _y;
    }
    Point operator -( const Point &b) const
    {
        return Point(x - b. x, y - b. y);
    }
    //叉积
    double operator ^ (const Point &b) const
    {
        return x*b. y - y*b. x;
    }
    //点积
    double operator * (const Point &b) const
    {
        return x*b. x + y*b. y;
    }
    //绕原点旋转角度B(弧度值),后x,y的变化
    void transXY(double B)
    {
        double tx = x,ty = y;
        x = tx* cos(B) - ty*sin(B);
        y = tx* sin(B) + ty*cos(B);
    }
};
Point p[47];

//*两点间距离
double dist( Point a, Point b)
{
    return sqrt((a-b)*(a- b));
}
//两个圆的公共部分面积
double Area_of_overlap(Point c1, double r1, Point c2, double r2)
{
    double d = dist(c1,c2);
    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*d);
    double t1 = acos(x / r1);
    double t2 = acos((d - x)/r2);
    return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
}

int main()
{
    double x1, y1, r1, x2, y2, r2;
    int t;
    int n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i = 0; i < n; i++)
        {
            scanf("%lf %lf %lf",&p[i].x,&p[i].y,&p[i].r);
        }
        double ans = 999999;
        double l, r, mid;
        for(int i = 0; i < n; i++) //枚举圆心
        {
            l = 0;
            r = 35000.0;//二分
            while(r-l > eps)//能找到
            {
                mid = (l+r)/2.0;
                int flag = 0;
                for(int j = 0; j < n; j++) // 每一个点
                {
                    if(Area_of_overlap(p[i],mid,p[j],p[j].r)<p[j].r*p[j].r*PI/2.0)
                    {
                        flag = 1;//太小
                        break;
                    }
                }
                if(flag)
                    l = mid;
                else
                    r = mid;
            }
            if(l < ans)
                ans = l;
        }
        printf("%.4lf\n",ans);
    }
    return 0;
}






本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5210854.html,如需转载请自行联系原作者

相关文章
|
机器人
hdu1035 Robot Motion(简单模拟题)
hdu1035 Robot Motion(简单模拟题)
39 0
poj 2362 hdoj 1518 Square(搜索)
不难了解,小棒子的长度越长,其灵活性越差。例如长度为5的一根棒子的组合方式要比5根长度为1的棒子的组合方式少,这就是灵活性的体现。
49 0
P3146 [USACO16OPEN]248 G
P3146 [USACO16OPEN]248 G
88 0
P3146 [USACO16OPEN]248 G
Google Earth Engine ——Landsat 8 8-Day BAI Composite烧伤面积指数BAI
Google Earth Engine ——Landsat 8 8-Day BAI Composite烧伤面积指数BAI
125 0
Google Earth Engine ——Landsat 8 8-Day BAI Composite烧伤面积指数BAI
Google Earth Engine ——MODIS Terra/Aqua Daily BAI烧伤面积指数(BAI)
Google Earth Engine ——MODIS Terra/Aqua Daily BAI烧伤面积指数(BAI)
131 0
Google Earth Engine ——MODIS Terra/Aqua Daily BAI烧伤面积指数(BAI)
|
编解码 安全 数据挖掘
Google Earth Engine ——数据全解析专辑(Copernicus Global Land Cover Layers: CGLS-LC100 Collec)2015 年全球土地分类数据集
Google Earth Engine ——数据全解析专辑(Copernicus Global Land Cover Layers: CGLS-LC100 Collec)2015 年全球土地分类数据集
264 0
Google Earth Engine ——数据全解析专辑(Copernicus Global Land Cover Layers: CGLS-LC100 Collec)2015 年全球土地分类数据集
HDOJ(HDU) 2309 ICPC Score Totalizer Software(求平均值)
HDOJ(HDU) 2309 ICPC Score Totalizer Software(求平均值)
100 0
|
人工智能 机器学习/深度学习