题解

我们先把所有点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. gulp+webpack配置

    转自:https://www.jianshu.com/p/2549c793bb27 gulp gulp是前端开发过程中对代码进行构建的工具,是自动化项目的构建利器:她不仅能对网站资源进行优化,而且在开 ...

  2. 动态规划:树形DP-景点中心(树的带权重心)

    话说宁波市的中小学生在镇海中学参加计算机程序设计比赛,比赛之余,他们在镇海中学的各个景点参观.镇海中学共有n个景点,每个景点均有若干学生正在参 观.这n个景点以自然数1至n编号,每两个景点的编号均不同 ...

  3. 记录第一次阿里云服务器部署java web工程的经历

    起因:测试一个微信小程序,发现所有的请求要求为https的形式,开发工具忽略后手机无法测试,故尝试配置. 准备:阿里云服务器一台 域名一个(解析在服务器)     tomcat7.0.54     j ...

  4. Eclipse中如何调整字体

    Eclipse 字体有两处,一处是控制台的字体,一处是主窗口.这里分别介绍控制台和主窗口字体的调节方法. Window -> Preferences -> General -> Ap ...

  5. Happy Matt Friends(HDU5119 + dp)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5119 题目: 题意: 求选择任意个数,使其异或和大于等于m的方案数. 思路: 每个数有选和不选两种方 ...

  6. async语法升级踩坑小记

    从今年过完年回来,三月份开始,就一直在做重构相关的事情. 就在今天刚刚上线了最新一次的重构代码,希望高峰期安好,接近半年的Node.js代码重构. 包含从callback+async.waterfal ...

  7. 【SLAM】安装 g2o_viewer

    2017年2月8日,那是一个阴天.为了完成高翔博士的<一起做RGB-D SLAM>教程,我在 Ubuntu 14.04 安装 g2o.遇到困难,怎奈我眼瞎,找错了方向,浪费时间,没有成功安 ...

  8. CSS3 transition过渡

    transition 属性是一个简写属性,用于设置四个过渡属性: transition: property duration timing-function delay; transition-pro ...

  9. ModelState验证部分属性

    ModelState.Remove("Name") 去掉不需要验证的属性.

  10. mysql -> 启动&多实例_03

    常用的连接方式: 套接字: mysql -uroot -p123 -S /application/mysql/tmp/mysql.sock Tcp/Ip: mysql -uroot -p123 -h ...