题目链接:
https://www.luogu.org/problemnew/show/P1742
This is codes:
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long //1844674407370955161
#define INT_INF 0x3f3f3f3f //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
const int maxn=1e6+100;
struct Point
{
double x,y;
Point() {}
Point(double x,double y):x(x),y(y) {}
} b[maxn];
Point O;
double R;
double pow_2(double x)//平方
{
return x*x;
}
double dis(Point x,Point y)//两点距离
{
return sqrt(pow_2(x.x-y.x)+pow_2(x.y-y.y));
}
bool incircle(Point x)//判断点是否在圆内
{
if(dis(O,x)<=R)
return true;
return false;
}
Point solve(int i,int j,int k)
{
double A=b[i].x-b[j].x;
double B=b[i].y-b[j].y;
double C=(pow_2(b[j].x)+pow_2(b[j].y)-pow_2(b[i].x)-pow_2(b[i].y))/2;
double D=b[i].x-b[k].x;
double E=b[i].y-b[k].y;
double F=(pow_2(b[k].x)+pow_2(b[k].y)-pow_2(b[i].x)-pow_2(b[i].y))/2;
double y=(F*A-C*D)/(B*D-E*A);
double x=(F*B-C*E)/(A*E-B*D);
return Point(x,y);
}
int main()
{
int n;//点的个数
scanf("%d",&n);
for(int i=1; i<=n; i++)//坐标
scanf("%lf%lf",&b[i].x,&b[i].y);
random_shuffle(b+1,b+n+1);//打乱元素排列,一定要有
R=0;
for(int i=1; i<=n; i++)//O(n^2)的时间
{
if(!incircle(b[i]))
{
O.x=b[i].x;
O.y=b[i].y;
R=0;
for(int 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(int k=1; k<j; k++)
{
if(!incircle(b[k]))
{
O=solve(i, j, k );
R=dis(b[i],O);
}
}
}
}
}
}
printf("%.10lf\n",R);//半径
printf("%.10lf %.10lf\n",O.x,O.y);//圆心
return 0;
}