hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分

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

二分

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#define eps 1e-10
#define PI acos(-1.0)
using namespace std;
struct point
{
    double x,y;
};
struct circle
{
    point c;
    double r;
}ci[50];
double dis(point p1,point p2)
{
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
double area(point p,double R,circle a)
{

    double d=dis(p,a.c),pp;
    double sa=0,ang1,ang2;
    ang1=acos((a.r*a.r+d*d-R*R)/(2*a.r*d));
    ang2=acos((R*R+d*d-a.r*a.r)/(2*R*d));
    pp=R*sin(ang2);
    sa=ang1*a.r*a.r+ang2*R*R-pp*d;
    return sa;
}
double qsearch(point p,circle a)
{
    double d=dis(p,a.c);
    double l=d,r=sqrt(d*d+a.r*a.r),mid;
    double ans=PI*a.r*a.r/2;
    while(l+eps<r)
    {
        mid=(l+r)/2;
        if(fabs(area(p,mid,a)-ans)<eps)
            return mid;
        else if(ans<area(p,mid,a))
            r=mid;
        else
            l=mid;
    }
    return l;
}
int main()
{
    int t,n;
    point p;
    circle a;
    p.x=2,p.y=0;
    a.c.x=0,a.c.y=0,a.r=1;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%lf%lf%lf",&ci[i].c.x,&ci[i].c.y,&ci[i].r);
        double minn;
        for(int i=0;i<n;i++)
        {
            double maxn=ci[i].r/sqrt(2.0);
            for(int j=0;j<n;j++)
            {
                if(i==j) continue;
                maxn=max(maxn,qsearch(ci[i].c,ci[j]));
            }
            if(i==0)
                minn=maxn;
            else
                minn=min(minn,maxn);
        }
        printf("%.4f\n",minn);
    }
    return 0;
}

  

时间: 2024-10-27 06:03:58

hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分的相关文章

hdu 3262 09 宁波 现场 C - Seat taking up is tough 暴力

Description Students often have problems taking up seats. When two students want the same seat, a quarrel will probably begin. It will have very bad effect when such subjects occur on the BBS. So, we urgently need a seat-taking-up rule. After several

hdu 3268 09 宁波 现场 I - Columbus’s bargain

Description On the evening of 3 August 1492, Christopher Columbus departed from Palos de la Frontera with a few ships, starting a serious of voyages of finding a new route to India. As you know, just in those voyages, Columbus discovered the America

[hdu 3264] Open-air shopping malls(二分+两圆相交面积)

题目大意是:先给你一些圆,你可以任选这些圆中的一个圆点作圆,这个圆的要求是:你画完以后.这个圆要可以覆盖之前给出的每一个圆一半以上的面积,即覆盖1/2以上每一个圆的面积. 比如例子数据,选左边还是选右边没差别,红色的圆为答案(选了左边的圆点),它覆盖了左边圆的1/2以上,也覆盖了右边圆的1/2以上. 知道了怎样求两圆面积交.那么这道题就简单了.仅仅要二分答案,然后枚举每个圆点,假设全都覆盖了1/2以上就继续二分,最后答案就得出来了. #include<iostream> #include<

hdu 3264 圆的交+二分

Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1822    Accepted Submission(s): 651 Problem Description The city of M is a famous shopping city and its open-air shopping

hdu 3264 Open-air shopping malls 求两圆相交

对每个圆二分半径寻找可行的最小半径,然后取最小的一个半径. 对于两圆相交就只要求到两个扇形,然后减去两个全等三角形就行了. #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> using namespace std; #define pi acos(-1.0) #define eps 1e-8 #define maxn 50 int n; struct point{

POJ 3831 &amp; 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

hdu 3264 Open-air shopping malls(求圆相交的面积,二分)

Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2256    Accepted Submission(s): 837 Problem Description The city of M is a famous shopping city and its open-air shopping

HDU 3264 区间内的最大最小之差

题目链接:http://poj.org/problem?id=3264 题目大意:在给定一堆牛的数量以及其高度的时候,每次给定一段区间,求这个区间内最高的牛和最矮的牛的高度之差为多少. 这道题目用线段树能快速的求解,因为此处不涉及更新,所以无需写update函数 不同于之前只定义一个tree数组,这回我们需要定义一个Max和一个Min数组分别子弟想存放较大和较小值 通过query找到区间内的最大值q,和最小值p,那么q-p便是我们所求的 1 #include <iostream> 2 #inc

HDU 3264 Open-air shopping malls (两个圆的交面积+二分)

题目链接 :HDU 3264 Open-air shopping malls 题意:给出n个圆.要求一个在n个圆的圆心建一个大圆,使大圆与每一个小圆的交面积大于等于该小圆的面积的一般.求最小的大圆半径. 思路:二分大圆半径,枚举每个小圆与大圆的交面积. 注意精度问题. AC代码: #include <stdio.h> #include <math.h> #include <algorithm> const double eps=1e-6; const double PI