HDU 3264——Open-air shopping malls

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

把题目中的在一个商场的中心理解成了在原点。。结果就错了

用到了求两个圆相交面积的模板。二分法。

代码如下:

#include<iostream>
#include<iomanip>
#include<vector>
#include<cmath>
using namespace std;
const double pi=acos(-1);

struct point{
	double x,y;
	point(double x,double y):x(x),y(y){}
};

typedef point Vector;

struct Circle{
	point c;
	double r;
	Circle(point c=point(0,0),double r=0):c(c),r(r) {}
	point Point(double a){
		return point(c.x+cos(a)*r,c.y+sin(a)*r);
	}
};

Circle mid[25];

Vector operator + (Vector a,Vector b){
	return Vector(a.x+b.x,a.y+b.y);
}

Vector operator - (Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}

Vector operator * (Vector a,double p){return Vector(a.x*p,a.y*p);}

double Dot(Vector a,Vector b){
	return a.x*b.x+a.y*b.y;
}

double Length(Vector a){
	return sqrt(Dot(a,a));
}

double Angle(Vector a,Vector b){
	return acos(Dot(a,b)/Length(a)/Length(b));
}

double angle(Vector v){return atan2(v.y,v.x);}

const double eps=1e-10;
int dcmp(double x){
	if(fabs(x)<eps)return 0;
	return x<0?-1:1;
}

double CircleCircleIntersetiontArea(Circle A,Circle B){
	point& p1=A.c;
	point& p2=B.c;
	double d=Length(p2-p1);
	double& r=B.r;
	double& R=A.r;
	if(dcmp(R+r-d)<=0)return 0;
	if(dcmp(R-r-d)>=0)return r*r*pi;
	if(dcmp(r-R-d)>=0)return R*R*pi;
	double a=acos((R*R+d*d-r*r)/2/R/d);
	double b=acos((r*r+d*d-R*R)/2/d/r);
	double S=R*R*a+r*r*b;
	S=S-R*d*sin(a);
	return S;
}

int main(){
//	freopen("data.txt","r",stdin);
	ios::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--){
		int n;
		cin>>n;
		for(int i=0;i<n;++i){
			cin>>mid[i].c.x>>mid[i].c.y>>mid[i].r;
		}
		double ret=20000;
		for(int t=0;t<n;++t){
			double tmp=0;
			for(int i=0;i<n;++i){
				Circle& D=mid[t];
				Circle& C=mid[i];
				double& r=mid[i].r;
				double d=Length(C.c-D.c);
				double R1=d;
				double R2=sqrt(d*d+r*r);
				double S=pi*r*r/2;
				while(fabs(R1-R2)>1e-6){
					if(dcmp(d)==0){R1=R2=sqrt(r*r/2);break;}
					double Rm=(R1+R2)/2;
					Circle O=Circle(D.c,Rm);
					double Sm=CircleCircleIntersetiontArea(O,C);
					if(dcmp(Sm-S)==0)R1=R2=Rm;
					else if(Sm<S)R1=Rm;
					else R2=Rm;
				}
				tmp=max(tmp,R1);
			}
			ret=min(ret,tmp);
		}
		cout<<setiosflags(ios::fixed)<<setprecision(4)<<ret<<endl;
	}
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值