题面

题解

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. 定制controller转场动画

    定制controller转场动画 从iOS7开始就可以自由定制控制器间的转场动画了,以下实例描述最简单的定制方式,达到的效果如下所示: 为了实现这个效果需要这么多的文件-_-!!!! RootView ...

  2. November 13th 2016 Week 47th Sunday The 1st Day

    Adventure may hurt you, but monotony will kill you. 也许冒险会让你受伤,但一成不变会让你灭亡. Just change a bit, let the ...

  3. tkinter入门,canvas实现百度,抖音,加载

    对于tkinter的各个控件,可以参看  : https://blog.csdn.net/weixin_38532159/article/details/78379523 这个已经比较全面了 今天利用 ...

  4. JavaScript验证字符串只能包含数字或者英文字符的代码实例

    验证字符串只能包含数字或者英文字符的代码实例:本章节分享一段代码实例,它实现了验证字符串内容是否只包含英文字符或者数字.代码实例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  5. iOS 开源库系列 Aspects核心源码分析---面向切面编程之疯狂的 Aspects

    Aspects的源码学习,我学到的有几下几点 Objective-C Runtime 理解OC的消息分发机制 KVO中的指针交换技术 Block 在内存中的数据结构 const 的修饰区别 block ...

  6. Js 中的事件委托/事件代理

    什么叫事件委托/事件代理呢 ? JavaScript高级程序设计上讲:事件委托就是利用事件冒泡,只指定一个事件处理程序,就可以管理某一类型的所有事件.   事件冒泡: 当事件发生后,这个事件就要开始传 ...

  7. 【jq】JQuery对select的操作

    下拉框 <select id="selectID" name="selectName"> <option vlaue="1" ...

  8. pipeline 发布war包

    pipline 写法分为 脚本式和声明式,下面采用脚本式编程: node { stage('checkout') { echo '开始检出代码' checkout([$class: 'GitSCM', ...

  9. block本质探寻四之copy

    说明: <1>阅读本文,最好阅读之前的block文章加以理解: <2>本文内容:三种block类型的copy情况(MRC).是否深拷贝.错误copy: 一.MRC模式下,三种b ...

  10. Math(初学)

    package day01; public class Case12 { public static void main(String[] args) { System.out.println(Mat ...