HDU-3264 (计算几何+二分)

问题描述:

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

题目题意:题目给我们n个圆的位置坐标和半径,然后让我们求一个大圆(它的圆心和某个小圆的圆心重合)能够至少覆盖每个小圆面积的一半的半径.

题目分析:由于题目给的小圆个数只有20个,所以我们可以枚举每一个小圆的圆心,然后二分去找半径,二分的判断条件就是让大圆与每个小圆相交求相交面积是否大于小圆的一半。

代码如下:

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

const double epx=1e-8;
const double inf=1e8;
const double PI=acos(-1.0);
int n;
struct note
{
    double x,y,r;
}point[25];

double area(struct note a,struct note b)//求的是俩圆的相交的面积(模板)
{
    double r1=a.r,r2=b.r;
    double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
	if (d >= r1+r2)
		return 0;
	if (r1>r2) swap (r1,r2);
	if(r2-r1 >= d)
		return PI*r1*r1;
	double ang1=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
	double ang2=acos((r2*r2+d*d-r1*r1)/(2*r2*d));
	return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
}
bool check (struct note o)
{
    for (int i=0;i<n;i++) {
        if (area(o,point[i])>=((point[i].r*point[i].r*PI)/2.0))//大于小圆的一半
            continue;
        else
            return false;
    }
    return true;
}
int main()
{
    int t;
    scanf("%d",&t);
    while (t--) {
        scanf("%d",&n);
        for (int i=0;i<n;i++)
            scanf("%lf%lf%lf",&point[i].x,&point[i].y,&point[i].r);
        double ans=inf;
        for (int i=0;i<n;i++) {//遍历每个小圆圆心
            struct note o=point[i];
            double left,right,mid;
            left=0,right=inf;
            while (right-left>epx) {
                mid=(left+right)/2;
                o.r=mid;//半径
                if (check(o)) right=mid;
                else left=mid;
            }
            ans=min(ans,left);
        }
        printf("%.4f\n",ans);
    }
    return 0;
}











  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值