首页 技术 正文
技术 2022年11月10日
0 收藏 839 点赞 3,820 浏览 1577 个字

【BZOJ2823】[AHOI2012]信号塔(最小圆覆盖)

题面

BZOJ

洛谷

相同的题:

BZOJ1

BZOJ2

洛谷

题解

模板题。。。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAX 1000100
const double eps=1e-10;
const double Pi=acos(-1);
struct Point{double x,y,ang;};
bool operator<(Point a,Point b){return (a.ang!=b.ang)?a.ang<b.ang:a.x<b.x;}
Point operator+(Point a,Point b){return (Point){a.x+b.x,a.y+b.y};}
Point operator-(Point a,Point b){return (Point){a.x-b.x,a.y-b.y};}
Point operator*(Point a,double b){return (Point){a.x*b,a.y*b};}
Point operator/(Point a,double b){return (Point){a.x/b,a.y/b};}
double operator*(Point a,Point b){return a.x*b.x+a.y*b.y;}
double Cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
double Len(Point a){return sqrt(a.x*a.x+a.y*a.y);}
double Dis(Point a,Point b){return Len(a-b);}
Point Rotate(Point p,double a){double c=cos(a),s=sin(a);return (Point){p.x*c-p.y*s,p.x*s+p.y*c};}
struct Line{Point a,v;};
Point Intersection(Line a,Line b)
{
Point c=b.a-a.a;
double t=Cross(b.v,c)/Cross(b.v,a.v);
return a.a+a.v*t;
}
Line GetHalfLine(Line a)
{
Point b=a.a+a.v*0.5;
return (Line){b,Rotate(a.v,Pi/2)};
}
struct Circle{Point o;double r;}O;
void GetCircle(Point *p,int n)
{
random_shuffle(&p[1],&p[n+1]);
for(int i=1;i<=n;++i)
if(Dis(O.o,p[i])>O.r)
{
O.o=p[i];O.r=0;
for(int j=1;j<i;++j)
if(Dis(O.o,p[j])>O.r)
{
O.o=(p[i]+p[j])*0.5;O.r=Dis(p[i],p[j])*0.5;
for(int k=1;k<j;++k)
if(Dis(O.o,p[k])>O.r)
{
O.o=Intersection(GetHalfLine((Line){p[i],p[j]-p[i]}),GetHalfLine((Line){p[i],p[k]-p[i]}));
O.r=Dis(O.o,p[i]);
}
}
}
printf("%.2lf %.2lf %.2lf\n",O.o.x,O.o.y,O.r);
}
int n;Point p[MAX];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%lf%lf",&p[i].x,&p[i].y);
GetCircle(p,n);
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,489
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,904
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,490
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,291