题解

我们先把所有点random_shuffle一下

然后对前i - 1个点计算一个最小圆覆盖,然后第i个点如果不在这个圆里,那么我们把这个点当成一个新的点,作为圆心,半径为0

从头枚举1 - i - 1,看看每个点在不在这个圆里,如果不在,那么就把新的点j,做一个圆经过i和j(就是i,j中点的作为圆心)

再枚举1 - j - 1,看看每个点在不在这个圆里,如果不在,那么新的点k,三点可以确定一个圆

写三个for就行

咦这不是\(n^3\)的吗

然而我们每个点只有\(\frac{3}{i}\)的概率被选上,复杂度是\(O(n)\)的

代码

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <bitset>
#include <queue>
#define enter putchar('\n')
#define space putchar(' ')
//#define ivorysi
#define pb push_back
#define mo 974711
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define MAXN 100005
#define eps 1e-12
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 - '0' + c;
c = getchar();
}
res = res * f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
struct Point {
db x,y;
Point(db _x = 0.0,db _y = 0.0) {
x = _x;y = _y;
}
friend Point operator + (const Point &a,const Point &b) {
return Point(a.x + b.x,a.y + b.y);
}
friend Point operator - (const Point &a,const Point &b) {
return Point(a.x - b.x,a.y - b.y);
}
friend Point operator * (const Point &a,const db &d) {
return Point(a.x * d,a.y * d);
}
friend db operator * (const Point &a,const Point &b) {
return a.x * b.y - a.y * b.x;
}
friend db dot(const Point &a,const Point &b) {
return a.x * b.x + a.y * b.y;
}
db norm() {
return sqrt(x * x + y * y);
}
}P[MAXN],C;
db R;
struct Seg {
Point a,b;
Seg(){}
Seg(Point _a,Point _b) {
a = _a;b = _b;
}
friend Point Cross_Point(const Seg &s,const Seg &t) {
db S1 = (s.a - t.a) * (t.b - t.a);
db S2 = (s.b - t.b) * (t.a - t.b);
return s.a + (s.b - s.a) * (S1 / (S1 + S2));
}
};
Point C_Point(Point a,Point b) {
return Point((a.x + b.x) * 0.5,(a.y + b.y) * 0.5);
}
int N;
void Solve() {
read(N);
db x,y;
for(int i = 1 ; i <= N ; ++i) {
scanf("%lf%lf",&x,&y);
P[i] = Point(x,y);
}
srand(20020421);
random_shuffle(P + 1,P + N + 1); C = P[1];
R = 0;
for(int i = 2 ; i <= N ; ++i) {
if((P[i] - C).norm() > R + eps) {
C = P[i];
R = 0;
for(int j = 1 ; j < i ; ++j) {
if((P[j] - C).norm() > R + eps) {
C = Point((P[i].x + P[j].x) * 0.5,(P[i].y + P[j].y) * 0.5);
R = (P[i] - C).norm();
for(int k = 1 ; k < j ; ++k) {
if((P[k] - C).norm() > R + eps) {
Point t1 = Point(P[j].y - P[k].y,P[k].x - P[j].x);
Point t2 = Point(P[i].y - P[k].y,P[k].x - P[i].x);
Point s1 = C_Point(P[k],P[j]);
Point s2 = C_Point(P[k],P[i]);
C = Cross_Point(Seg(s1,s1 + t1),Seg(s2,s2 + t2));
R = (P[k] - C).norm();
}
}
}
}
}
}
printf("%.10lf\n",R);
printf("%.10lf %.10lf\n",C.x,C.y);
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【BZOJ】1336: [Balkan2002]Alien最小圆覆盖的更多相关文章

  1. [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】

    题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...

  2. Bzoj 1336&1337 Alien最小圆覆盖

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special Judge Submit: 1473  ...

  3. bzoj2823: [AHOI2012]信号塔&&1336: [Balkan2002]Alien最小圆覆盖&&1337: 最小圆覆盖

    首先我写了个凸包就溜了 这是最小圆覆盖问题,今晚学了一下 先随机化点,一个个加入 假设当前圆心为o,半径为r,加入的点为i 若i不在圆里面,令圆心为i,半径为0 再重新从1~i-1不停找j不在圆里面, ...

  4. BZOJ 1337: 最小圆覆盖1336: [Balkan2002]Alien最小圆覆盖(随机增量法)

    今天才知道有一种东西叫随机增量法就来学了= = 挺神奇的= = A.令ci为包括前i个点的最小圆,若第i+1个点无法被ci覆盖,则第i+1个点一定在ci+1上 B.令ci为包括前i个点的最小圆且p在边 ...

  5. bzoj1336: [Balkan2002]Alien最小圆覆盖

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1336 1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 ...

  6. BZOJ1336 Balkan2002 Alien最小圆覆盖 【随机增量法】*

    BZOJ1336 Balkan2002 Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000, ...

  7. 【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法

    [BZOJ1336][Balkan2002]Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=10000 ...

  8. 【bzoj1336/1337/2823】[Balkan2002]Alien最小圆覆盖 随机增量法

    题目描述 给出N个点,让你画一个最小的包含所有点的圆. 输入 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000. ...

  9. 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1573   ...

随机推荐

  1. 流媒体技术学习笔记之(十六)H264编码profile & level控制

    H.264有四种画质级别,分别是baseline, extended, main, high: 1.Baseline Profile:基本画质.支持I/P 帧,只支持无交错(Progressive)和 ...

  2. angularJS $resource

    $resource是一个更方便地与RESTful服务器API进行交互,可以方便地定义一个REST资源,而不必手动所有的声明CRUD方法的Service. 使用 1.要使用$resource首先要在HT ...

  3. [转载]IIS6.0开启WOFF/SVG文件支持

    http://www.bao21.com/120.html http://stackoverflow.com/questions/18369036/bootstrap-3-glyphicons-not ...

  4. Is It A Tree? 挂着并查集的帽子招摇撞骗

    Description A tree is a well-known data structure that is either empty (null, void, nothing) or is a ...

  5. 正在载入中......loading页面的几种方法

    网页加载过程中提示“载入中…”,特别是使用动画效果,可以一个“等待”的温馨提示,用户体验很不错.下面介绍几种方法. 第一种: 原理就是,在网页载入时在页面最中间打入一个层上面显示,"网页正在 ...

  6. 字典树&&01字典树专题&&对字典树的理解

    对于字典树和01字典树的一点理解: 首先,字典树建树的过程就是按照每个数的前缀来的,如果你要存储一个全小写字母字符串,那么这个树每一个节点最多26个节点,这样的话,如果要找特定的单词的话,按照建树的方 ...

  7. mnist 手写数字识别

    mnist 手写数字识别三大步骤 1.定义分类模型2.训练模型3.评价模型 import tensorflow as tfimport input_datamnist = input_data.rea ...

  8. Unix/Linux系统时间函数API

    首先说明关于几个时间的概念: 世界时:起初,国际上的标准时间是格林尼治标准时间,以太阳横穿本初子午线的时刻为标准时间正午12点.它根据天文环境来定义,就像古代人们根据日晷来计时一样,如下图: 原子时: ...

  9. UNIX网络编程 第3章 套接字编程简介

    套接字结构类型和相关的格式转换函数

  10. [转]使用 C++11 编写 Linux 多线程程序

    前言 在这个多核时代,如何充分利用每个 CPU 内核是一个绕不开的话题,从需要为成千上万的用户同时提供服务的服务端应用程序,到需要同时打开十几个页面,每个页面都有几十上百个链接的 web 浏览器应用程 ...