HDU/HDOJ 3264 计算几何+二分 2009 宁波区域赛

 

Open-air shopping malls

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 630    Accepted Submission(s): 204


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
   
   
   
   
1 2 0 0 1 2 0 1
 

Sample Output
   
   
   
   
2.0822
 

Source
2009 Asia Ningbo Regional Contest Hosted by NIT
 


可以直接二分大圆的半径R

然后分别枚举两个圆

取一个最小半径即可

 

我的代码:

#include<stdio.h>
#include<math.h>
#include<algorithm>
#define pi acos(-1.0)

using namespace std;

struct circle
{
    double x;
    double y;
    double r;
};
circle p[25];

double dis(int a,int b)
{
    return sqrt((p[a].x-p[b].x)*(p[a].x-p[b].x)+(p[a].y-p[b].y)*(p[a].y-p[b].y));
}

bool judge(double R,double r,double d)
{
    double sita1,sita2,area1,area2,area;
    sita1=2.0*acos((R*R+d*d-r*r)/(2.0*R*d));
    sita2=2.0*acos((r*r+d*d-R*R)/(2.0*r*d));
    area1=R*R*(sita1-sin(sita1))/2.0;
    area2=r*r*(sita2-sin(sita2))/2.0;
    area=0.5*pi*r*r;
    if(area1+area2<=area)
        return true;
    else
        return false;
}

double solve(int i,int j)
{
    double left,right,mid,x;
    int k;
    x=left=dis(i,j);
    right=sqrt(x*x+p[j].r*p[j].r);
    for(k=1;k<=30;k++)
    {
        mid=(left+right)/2.0;
        if(judge(mid,p[j].r,x))
            left=mid;
        else
            right=mid;
    }
    return left;
}

int main()
{
    int i,j,t,n;
    double temp,ans[25];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
            ans[i]=0;
        }
        if(n==1)
        {
            printf("%.4lf\n",sqrt(0.5)*p[1].r);
            continue;
        }
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(i==j)
                    continue;
                temp=solve(i,j);
                if(temp>ans[i])
                    ans[i]=temp;
            }
        }
        sort(ans+1,ans+n+1);
        printf("%.4lf\n",ans[1]);
    }
    return 0;
}


 

你可能感兴趣的:(manager,Integer,less,input,each,output)