标签:shuffle main const mat mes ace printf oid blog
主要是我太菜了不会证明qwq,上面的博客讲的非常好。
主要是存代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=100009;
const double eps=1e-10;
int n;
struct Point
{
double x,y;
Point() {}
Point(double X,double Y) :x(X),y(Y) {}
Point operator + (const Point a)const { return Point(x+a.x,y+a.y); }
Point operator - (const Point a)const { return Point(x-a.x,y-a.y); }
Point operator * (const double a)const { return Point(x*a,y*a); }
Point operator / (const double a)const { return Point(x/a,y/a); }
double operator * (const Point a)const { return x*a.y-y*a.x; }
void read() { scanf("%lf %lf",&x,&y); }
void print() { printf("%.10lf %.10lf\n",x,y); }
}a[N];
Point cross(Point p1,Point v1,Point p2,Point v2)
{
double t=((p2-p1)*v2)/(v1*v2);
return p1+v1*t;
}
double dis(Point a,Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
Point rotate_90(Point p)
{
return Point(p.y,-p.x);
}
Point circle(Point p1,Point p2,Point p3)
{
return cross((p1+p2)/2,rotate_90(p2-p1),(p1+p3)/2,rotate_90(p3-p1));
}
void init()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
a[i].read();
}
void work()
{
Point O(0,0);
double r=0.;
random_shuffle(a+1,a+1+n);
for (int i=1;i<=n;i++)
if(dis(O,a[i])>r+eps)
{
O=a[i],r=0;
for (int j=1;j<i;j++)
if(dis(O,a[j])>r+eps)
{
O=(a[i]+a[j])/2,r=dis(a[i],a[j])/2;
for (int k=1;k<j;k++)
if(dis(O,a[k])>r+eps)
{
O=circle(a[i],a[j],a[k]);
r=dis(O,a[i]);
}
}
}
printf("%.10lf\n",r);
O.print();
}
int main()
{
init();
work();
return 0;
}
标签:shuffle main const mat mes ace printf oid blog
原文地址:https://www.cnblogs.com/With-penguin/p/13228783.html