BZOJ 1337 最小圆覆盖 随机增量法

题目大意:求最小圆覆盖

我又写了一遍233

尼玛上一遍居然忘记random_shuffle了= =

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define M 100100
#define EPS 1e-7
using namespace std;
struct Point{
	double x,y;
	Point() {}
	Point(double _,double __):
		x(_),y(__) {}
	friend istream& operator >> (istream &_,Point &p)
	{
		scanf("%lf%lf",&p.x,&p.y);
		return _;
	}
	friend Point operator + (const Point &p1,const Point &p2)
	{
		return Point(p1.x+p2.x,p1.y+p2.y);
	}
	friend Point operator - (const Point &p1,const Point &p2)
	{
		return Point(p1.x-p2.x,p1.y-p2.y);
	}
	friend double operator * (const Point &p1,const Point &p2)
	{
		return p1.x*p2.y-p1.y*p2.x;
	}
	friend Point operator * (const Point &p1,double rate)
	{
		return Point(p1.x*rate,p1.y*rate);
	}
	friend double Distance(const Point &p1,const Point &p2)
	{
		return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) ) ;
	}
	friend Point Rotate(const Point &p)
	{
		return Point(-p.y,p.x);
	}
}points[M];
struct Line{
	Point p,v;
	Line() {}
	Line(const Point &_,const Point &__):
		p(_),v(__) {}
	friend Point Get_Intersection(const Line &l1,const Line &l2)
	{
		Point u=l1.p-l2.p;
		double temp=(l2.v*u)/(l1.v*l2.v);
		return l1.p+l1.v*temp;
	}
};
struct Circle{
	Point o;
	double r;
	Circle() {}
	Circle(const Point &_,double __):
		o(_),r(__) {}
	bool In_Circle(const Point &p)
	{
		return Distance(p,o) < r + EPS ;
	}
}ans;
int n;
int main()
{
	int i,j,k;
	srand(19980402);
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>points[i];
	random_shuffle(points+1,points+n+1);
	for(i=1;i<=n;i++)
	{
		if(!ans.In_Circle(points[i]))
		{
			ans=Circle(points[i],0);
			for(j=1;j<i;j++)
				if(!ans.In_Circle(points[j]))
				{
					ans=Circle((points[i]+points[j])*0.5,Distance(points[i],points[j])*0.5);
					for(k=1;k<j;k++)
						if(!ans.In_Circle(points[k]))
						{
							Line l1=Line((points[i]+points[j])*0.5,Rotate(points[i]-points[j]));
							Line l2=Line((points[i]+points[k])*0.5,Rotate(points[i]-points[k]));
							Point O=Get_Intersection(l1,l2);
							ans=Circle(O,Distance(points[i],O));
						}
				}
		}
	}
	cout<<fixed<<setprecision(3)<<ans.r<<endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值