The world king Sconbin is not the exception.One day,Sconbin was sleeping,then swakened by one nightmare.It turned out that his love letters to Dufein were made public in his dream.These foolish letters might ruin his throne.Sconbin decided to destroy the letters by the military exercises's opportunity.The missile is the best weapon.Considered the execution of the missile,Sconbin chose to use one missile with the minimum destruction.
Sconbin had writen N letters to Dufein, she buried these letters on different places.Sconbin got the places by difficult,he wants to know where is the best place launch the missile,and the smallest radius of the burst area. Let's help Sconbin to get the award.
3 1.00 1.00 2.00 2.00 3.00 3.00 0
2.00 2.00 1.41
题意,给你一些点,然后让你求出能全部覆盖这些点的最小圆
直接最小圆覆盖算法 http://blog.csdn.net/tianyuhang123/article/details/53761400
ac代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 100010
using namespace std;
struct node
{
double x,y;
} b[N];
node O;
double R;
double sqr(double x)
{
return x*x;
}
double dis(node x,node y)
{
return sqrt(sqr(x.x-y.x)+sqr(x.y-y.y));
}
bool incircle(node x)
{
if(dis(O,x)<=R) return true;
return false;
}
node solve(double a,double b,double c,double d,double e,double f)
{
double y=(f*a-c*d)/(b*d-e*a);
double x=(f*b-c*e)/(a*e-b*d);
return (node)
{
x,y
};
}
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
int i,j,k;
for(i=1; i<=n; i++)
scanf("%lf%lf",&b[i].x,&b[i].y);
R=0;
for(i=1; i<=n; i++)
if(!incircle(b[i]))
{
O.x=b[i].x;
O.y=b[i].y;
R=0;
for(j=1; j<i; j++)
if(!incircle(b[j]))
{
O.x=(b[i].x+b[j].x)/2;
O.y=(b[i].y+b[j].y)/2;
R=dis(O,b[i]);
for(k=1; k<j; k++)
if(!incircle(b[k]))
{
O=solve(
b[i].x-b[j].x,b[i].y-b[j].y,(sqr(b[j].x)+sqr(b[j].y)-sqr(b[i].x)-sqr(b[i].y))/2,
b[i].x-b[k].x,b[i].y-b[k].y,(sqr(b[k].x)+sqr(b[k].y)-sqr(b[i].x)-sqr(b[i].y))/2
);
R=dis(b[i],O);
}
}
}
printf("%.2lf %.2lf %.2lf\n",O.x,O.y,R);
}
}