HDU3264 Open-air shopping malls (圆交+二分)

题目链接:

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

题意:

给定n个圆的圆心和半径,求一个圆心为这些圆中任意一个,与所有圆相交的面积超过其面积一半的圆的最小半径。

分析:

枚举圆心,然后二分得到最小的半径,直接套求圆交的模板。

代码如下:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

const double eps = 1e-8;

const double pi = acos(-1.0);

int n;

struct point
{
    double x,y,r;
}cir[25];

double S(point a)
{
    return pi*a.r*a.r;
}

double dis(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double calu(point a,point b)
{
    point tmpa=a,tmpb=b;
    if(tmpa.r<tmpb.r) swap(tmpa,tmpb);
    double area = 0;
    double dd = dis(tmpa,tmpb);
    if(dd>tmpa.r-tmpb.r&&dd<tmpa.r+tmpb.r){
        double cos1 = (tmpa.r*tmpa.r+dd*dd-tmpb.r*tmpb.r)/(2*tmpa.r*dd);
        double cos2 = (tmpb.r*tmpb.r+dd*dd-tmpa.r*tmpa.r)/(2*tmpb.r*dd);
        double th1 = 2*acos(cos1);
        double th2 = 2*acos(cos2);
        double s1 = 0.5*tmpa.r*tmpa.r*sin(th1);
        double s2 = 0.5*tmpb.r*tmpb.r*sin(th2);
        double s3 = (th1/2)*tmpa.r*tmpa.r;
        double s4 = (th2/2)*tmpb.r*tmpb.r;
        area = s3+s4-s1-s2;
    }
    else if(dd<=tmpa.r-tmpb.r)
        area = S(tmpb);
    return area;
}

bool check(point a)
{
    for(int i=0;i<n;i++){
        if(calu(a,cir[i])*2<pi*cir[i].r*cir[i].r)
            return false;
    }
    return true;
}

double bin_search(double l,double r,point tmp)
{
    double mid;
    while(r-l>=eps){
        mid=(l+r)/2.0;
        tmp.r=mid;
        if(check(tmp)) r=mid;
        else l=mid+eps;
    }
    return mid;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=0;i<n;i++)
            scanf("%lf%lf%lf",&cir[i].x,&cir[i].y,&cir[i].r);
        point ans;
        double r=1000000;
        for(int i=0;i<n;i++){
            ans.x=cir[i].x,ans.y=cir[i].y;
            r=min(r,bin_search(0,30000,ans));
        }
        printf("%.4lf\n",r);
    }
    return 0;
}
时间: 2024-08-01 21:21:12

HDU3264 Open-air shopping malls (圆交+二分)的相关文章

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

Open-air shopping malls(二分半径,两元交面积)

http://acm.hdu.edu.cn/showproblem.php?pid=3264 Open-air shopping malls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2139    Accepted Submission(s): 775 Problem Description The city of M is a

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 Open-air shopping malls(圆相交面积+二分)

HDU 3264 Open-air shopping malls(圆相交面积+二分) ACM 题目地址:HDU 3264 Open-air shopping malls 题意: 给出一些圆,选择其中一个圆的圆心为圆心,然后画一个大圆,要求大圆最少覆盖每个圆的一半面积.求最小面积. 分析: 枚举每个点,用二分求出需要的圆,更新最小值即可. 其中用到了圆相交面积,可以参考这题: POJ 2546 Circular Area(两个圆相交面积) 代码: /* * Author: illuz <iillu

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{

hdu3264Open-air shopping malls(二分)

链接 枚举伞的圆心,最多只有20个,因为必须与某个现有的圆心重合. 然后再二分半径就可以了. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9

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

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