题面

题解

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】信号塔的更多相关文章

  1. bzoj2823[AHOI2012]信号塔

    2823: [AHOI2012]信号塔 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1190  Solved: 545[Submit][Status ...

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

    [BZOJ2823][AHOI2012]信号塔(最小圆覆盖) 题面 BZOJ 洛谷 相同的题: BZOJ1 BZOJ2 洛谷 题解 模板题... #include<iostream> #i ...

  3. 2018.07.04 BZOJ 2823: AHOI2012信号塔(最小圆覆盖)

    2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MB Description 在野外训练中,为了确保每位参加集训的成员安全,实时的掌握 ...

  4. 【BZOJ】2823: [AHOI2012]信号塔

    题意 给\(n\)个点,求一个能覆盖所有点的面积最小的圆.(\(n \le 50000\)) 分析 随机增量法 题解 理论上\(O(n^3)\)暴力,实际上加上随机化后期望是\(O(n)\)的. 算法 ...

  5. 【bzoj2823】 AHOI2012—信号塔

    http://www.lydsy.com/JudgeOnline/problem.php?id=2823 (题目链接) 题意 求最小圆覆盖 Solution 关于最小圆覆盖的做法,论文里面都有.其实真 ...

  6. BZOJ 2823: [AHOI2012]信号塔

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2823 随机增量法.不断加点维护圆,主要是三点共圆那里打得烦(其实也就是个两中垂线求交点+联立方 ...

  7. BZOJ.2823.[AHOI2012]信号塔(最小圆覆盖 随机增量法)

    BZOJ 洛谷 一个经典的随机增量法,具体可以看这里,只记一下大体流程. 一个定理:如果一个点\(p\)不在点集\(S\)的最小覆盖圆内,那么它一定在\(S\bigcup p\)的最小覆盖圆上. 所以 ...

  8. AHOI2012 信号塔 | 最小圆覆盖模板

    题目链接:戳我 最小圆覆盖. 1.枚举第一个点,考虑当前圆是否包含了这个点,如果没有,则把圆变成以这个点为圆心,半径为0的圆. 2.枚举第二个点,考虑圆是否包含了这个点,如果没有,则把圆变成以这两个点 ...

  9. BZOJ2823 [AHOI2012]信号塔 【最小圆覆盖】

    题目链接 BZOJ2823 题解 最小圆覆盖模板 都懒得再写一次 #include<iostream> #include<cstdio> #include<cmath&g ...

  10. bzoj 2823: [AHOI2012]信号塔 最小圆覆盖

    题目大意: 给定n个点,求面积最小的园覆盖所有点.其中\(n \leq 10^6\) 题解: 恩... 刚拿到这道题的时候... 什么???最小圆覆盖不是\(O(n^3)\)的随机增量算法吗????? ...

随机推荐

  1. 卸载oracle 10g

    1.开始->设置->控制面板->管理工具->服务——>   停止所有Oracle服务.(没有起动的就不用停用了)2.开始->程序->Oracle - OraD ...

  2. Flask的错误日志处理和|ORM操作

    flask有个很人性化的处理就是 你的错误的输出是可以通过错误日志来自定义  ,让你输入的错误不再是“大黄页”, 通过 errorhandler()来装饰函数之后你的所有的输入错误的函数你都会进入这个 ...

  3. 使用linux远程登录另一台linux

    可以用ssh命令行方式登录.对方需要开启ssh服务.   ssh [-l login_name] [-p port] [user@]hostname   例如,使用root用户登录 192.168.0 ...

  4. October 1st 2017 Week 40th Sunday

    It's only after we've lost everything that we're free to do anything. 只有我们失去了所有之后我们才能随心而为. After los ...

  5. python3编程的一些实用技巧1

    1.choice函数:返回一个列表,元组,字符串的随机项   :   调用时应导入random模块,如from random import choice 2.print 两个字符串, 逗号,+号进行连 ...

  6. 【原创】python requests 库底层Sockets处于close_wait状态

    以前对于Requests库只是简单是使用,在现在公司的后台中,有多个接口是直接使用requests.get .post之类的方法来做的,进行过一段时间的压力测试,发现性能低的可怜,且linux服务器有 ...

  7. JavaScript创建对象的6种方式

    JavaScript创建对象简单的说,无非就是使用内置对象(Object)或各种自定义对象,当然还可以用JSON,但写法有很多种,也能混合使用. 1.对象字面量的方式 person = {name : ...

  8. jQuery 和 YUI (Yahoo User Interface) 各自的优缺点有哪些?具体的使用场景是怎样的?

    张经纬,前端工程师 知乎用户.赵勇杰.知乎用户 等人赞同 其实jQuery和YUI的侧重点是不一样的. jQuery专注于DOM的操作,他通过继承的方式给传入的对象增加了新的方法,从而使我们可以通过链 ...

  9. android小游戏模版—重力感应

               好久没更新博客了,今天来谈谈android小游戏---重力感应,一般在游戏里运用的比較多,比方这类游戏有:神庙逃亡.极品飞车,平衡球.三围重力迷宫,重力赛车等. 首先什么是重力感 ...

  10. 一些需要禁用的PHP危险函数

    phpinfo()功能描述:输出 PHP 环境信息以及相关的模块.WEB 环境等信息.危险等级:中 passthru()功能描述:允许执行一个外部程序并回显输出,类似于 exec().危险等级:高 e ...