【AHOI2012】信号塔
题面
题解
xgzc怒切计算几何
最小圆覆盖板子题
整体算法如下:
枚举第一个点,考虑当前圆是否包含了这个点,如果没有,则把圆变成以这个点为圆心,半径为\(0\)的圆。再枚举第二个点,考虑圆是否包含了这个点,如果没有,则把圆变成以这两个点的中点为圆心,半径为两点距离一半的圆。再枚举第三个点,节点是否在圆内,如果不在,则把圆直接变成这三个点的外接圆。
\(n^3\)过百万???是的
我们随机打乱点,这样的期望是\(O(n)\)的
代码
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<algorithm>
#define RG register
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define clear(x, y) memset(x, y, sizeof(x))
inline int read()
{
int data = 0, w = 1; char ch = getchar();
while(ch != '-' && (!isdigit(ch))) ch = getchar();
if(ch == '-') w = -1, ch = getchar();
while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
return data * w;
}
const int maxn(1e6 + 10);
const double eps(1e-10), pi(acos(-1));
struct point { double x, y; };
struct line { point a, v; };
struct circle { point o; double r; } O;
typedef point vector;
inline vector operator + (const vector &lhs, const vector &rhs)
{ return (vector) {lhs.x + rhs.x, lhs.y + rhs.y}; }
inline vector operator - (const vector &lhs, const vector &rhs)
{ return (vector) {lhs.x - rhs.x, lhs.y - rhs.y}; }
inline vector operator * (const vector &lhs, const double &rhs)
{ return (vector) {lhs.x * rhs, lhs.y * rhs}; }
inline vector operator / (const vector &lhs, const double &rhs)
{ return (vector) {lhs.x / rhs, lhs.y / rhs}; }
inline double operator * (const vector &lhs, const vector &rhs)
{ return lhs.x * rhs.x + lhs.y * rhs.y; }
inline double cross(const vector &lhs, const vector &rhs)
{ return lhs.x * rhs.y - lhs.y * rhs.x; }
inline double Len(const vector &a) { return sqrt(a.x * a.x + a.y * a.y); }
inline double Dis(const point &a, const point &b) { return Len(a - b); }
inline vector rotate(const vector &lhs, const double &ang)
{
double c = cos(ang), s = sin(ang);
return (vector) {lhs.x * c - lhs.y * s, lhs.x * s + lhs.y * c};
}
point Intersection(const line &a, const line &b)
{
vector c = b.a - a.a;
double t = cross(b.v, c) / cross(b.v, a.v);
return a.a + a.v * t;
}
line half(const line &a)
{
point b = a.a + a.v * .5;
return (line) {b, rotate(a.v, pi * .5)};
}
void getCircle(point p[], int n)
{
std::random_shuffle(p + 1, p + n + 1);
for(RG int i = 1; i <= n; ++i)
if(Dis(O.o, p[i]) > O.r)
{
O.o = p[i], O.r = 0;
for(RG int j = 1; j < i; j++)
if(Dis(O.o, p[j]) > O.r)
{
O.o = (p[i] + p[j]) * .5, O.r = Dis(p[i], p[j]) * .5;
for(RG int k = 1; k < j; k++)
if(Dis(O.o, p[k]) > O.r)
O.o = Intersection(half((line) {p[i], p[j] - p[i]}),
half((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[maxn];
int main()
{
srand(time(NULL)); scanf("%d", &n);
for(RG int i = 1; i <= n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
getCircle(p, n);
return 0;
}
【AHOI2012】信号塔的更多相关文章
- bzoj2823[AHOI2012]信号塔
2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1190 Solved: 545[Submit][Status ...
- 【BZOJ2823】[AHOI2012]信号塔(最小圆覆盖)
[BZOJ2823][AHOI2012]信号塔(最小圆覆盖) 题面 BZOJ 洛谷 相同的题: BZOJ1 BZOJ2 洛谷 题解 模板题... #include<iostream> #i ...
- 2018.07.04 BZOJ 2823: AHOI2012信号塔(最小圆覆盖)
2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MB Description 在野外训练中,为了确保每位参加集训的成员安全,实时的掌握 ...
- 【BZOJ】2823: [AHOI2012]信号塔
题意 给\(n\)个点,求一个能覆盖所有点的面积最小的圆.(\(n \le 50000\)) 分析 随机增量法 题解 理论上\(O(n^3)\)暴力,实际上加上随机化后期望是\(O(n)\)的. 算法 ...
- 【bzoj2823】 AHOI2012—信号塔
http://www.lydsy.com/JudgeOnline/problem.php?id=2823 (题目链接) 题意 求最小圆覆盖 Solution 关于最小圆覆盖的做法,论文里面都有.其实真 ...
- BZOJ 2823: [AHOI2012]信号塔
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2823 随机增量法.不断加点维护圆,主要是三点共圆那里打得烦(其实也就是个两中垂线求交点+联立方 ...
- BZOJ.2823.[AHOI2012]信号塔(最小圆覆盖 随机增量法)
BZOJ 洛谷 一个经典的随机增量法,具体可以看这里,只记一下大体流程. 一个定理:如果一个点\(p\)不在点集\(S\)的最小覆盖圆内,那么它一定在\(S\bigcup p\)的最小覆盖圆上. 所以 ...
- AHOI2012 信号塔 | 最小圆覆盖模板
题目链接:戳我 最小圆覆盖. 1.枚举第一个点,考虑当前圆是否包含了这个点,如果没有,则把圆变成以这个点为圆心,半径为0的圆. 2.枚举第二个点,考虑圆是否包含了这个点,如果没有,则把圆变成以这两个点 ...
- BZOJ2823 [AHOI2012]信号塔 【最小圆覆盖】
题目链接 BZOJ2823 题解 最小圆覆盖模板 都懒得再写一次 #include<iostream> #include<cstdio> #include<cmath&g ...
- bzoj 2823: [AHOI2012]信号塔 最小圆覆盖
题目大意: 给定n个点,求面积最小的园覆盖所有点.其中\(n \leq 10^6\) 题解: 恩... 刚拿到这道题的时候... 什么???最小圆覆盖不是\(O(n^3)\)的随机增量算法吗????? ...
随机推荐
- 关于nicescroll滚动条现在浏览器上滚动问题
nativeparentscrolling: false //检测内容底部,并让父节点来滚动,作为原生滚动 有时候 当自定义滚动条在底部 滚动无效 可以把这个参数设置一下
- 【Redis】命令学习笔记——键(key)(20个超全字典版)
安装完redis和redis-desktop-manager后,开始学习命令啦!本篇基于redis 4.0.11版本,从对键(key)开始挖坑! 准备工作,使用db1(默认db0,由于之前练习用db0 ...
- pandas模块安装问题笔记
1. # pip install pandas 引用 pandas 时,没有模块 ,进行模块安装,出现一推英文提示 结果 Collecting pandas Could not fetch URL ...
- Python学习---xml文件的解析[beautifulsoup4模块学习]
1.1. 安装beautifulsoup4 pip install beautifulsoup4 [更多参考]https://blog.csdn.net/sunhuaqiang1/article/de ...
- Linux cal命令详解
cal 显示指定月份的日历 常见命令参数 NAME cal - displays a calendar SYNOPSIS cal [-smjy13] [[[day] month] year] DESC ...
- 关于Tomcat端口出现的问题
=Several ports (8005, 8080, 8009) required by Tomcat v7.0 Server at localhost are already in use. Th ...
- mysql的表和约束操作
在创建表是默认为加上数据引擎和字符集,如创建一个student表,代码如下: create table students(id int unsigned zerofill auto_increment ...
- Python之数据库模块安装 MySQLdb
安装,下载地址 安装可能会报错, 1.需要安装VC++,到提示的地址中下载安装即可 2.在下载对应的包版本,如果是win7 64位2.7版本的python,就下载 MySQL_python-1.2.5 ...
- SGU---102 欧拉函数
题目链接: https://cn.vjudge.net/problem/SGU-102#author=0 题目大意: 求解小于等于N的且与N互质的数字有多少个 解题思路: 直接求欧拉函数即可 关于欧拉 ...
- python第十四课--排序及自定义函数之案例一:选择排序
案例一:选择排序使用选择排序的思想实现列表数据的升序排序 lt=[45,12,56,-32,-3,44,75,-22,100] length=len(lt) # print('排序前:'+str(lt ...