【BZOJ】1336: [Balkan2002]Alien最小圆覆盖
题解
我们先把所有点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最小圆覆盖的更多相关文章
- [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】
题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...
- Bzoj 1336&1337 Alien最小圆覆盖
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special Judge Submit: 1473 ...
- bzoj2823: [AHOI2012]信号塔&&1336: [Balkan2002]Alien最小圆覆盖&&1337: 最小圆覆盖
首先我写了个凸包就溜了 这是最小圆覆盖问题,今晚学了一下 先随机化点,一个个加入 假设当前圆心为o,半径为r,加入的点为i 若i不在圆里面,令圆心为i,半径为0 再重新从1~i-1不停找j不在圆里面, ...
- BZOJ 1337: 最小圆覆盖1336: [Balkan2002]Alien最小圆覆盖(随机增量法)
今天才知道有一种东西叫随机增量法就来学了= = 挺神奇的= = A.令ci为包括前i个点的最小圆,若第i+1个点无法被ci覆盖,则第i+1个点一定在ci+1上 B.令ci为包括前i个点的最小圆且p在边 ...
- bzoj1336: [Balkan2002]Alien最小圆覆盖
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1336 1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 ...
- BZOJ1336 Balkan2002 Alien最小圆覆盖 【随机增量法】*
BZOJ1336 Balkan2002 Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000, ...
- 【BZOJ1336】[Balkan2002]Alien最小圆覆盖 随机增量法
[BZOJ1336][Balkan2002]Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=10000 ...
- 【bzoj1336/1337/2823】[Balkan2002]Alien最小圆覆盖 随机增量法
题目描述 给出N个点,让你画一个最小的包含所有点的圆. 输入 先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000. ...
- 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)
1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 1573 ...
随机推荐
- 转:iPhone上关于相机拍照的图片的imageOrientation的问题
用相机拍摄出来的照片含有EXIF信息,UIImage的imageOrientation属性指的就是EXIF中的orientation信息.如果我们忽略orientation信息,而直接对照片进行像素处 ...
- Linux基础命令【记录】
后台运行详情:https://www.cnblogs.com/little-ant/p/3952424.html 查看端口.查找等命令 根据关键字查找文件信息: cat <文件名> | g ...
- Java并发编程原理与实战三十六:阻塞队列&消息队列
一.阻塞队列 1.阻塞队列BlockingQueue ---->可以理解成生产者消费者的模式---->消费者要等待到生产者生产出来产品.---->而非阻塞队列ConcurrentLi ...
- CentOS 7快速入门系列教程(一)
基本命令 ls 列举当前目录下的所有文件夹 ls -l 查看文件还是文件夹 d表示文件夹 -表示文件 ls --help man ls 询问命令 man 3 malloc 查看函数 cd 跳转 ...
- Is it possible to create @Around Aspect for feign.Client
https://github.com/spring-cloud/spring-cloud-openfeign/issues/59 看到github 有人问这个问题,做了个示例: import org. ...
- 早该知道的7个JavaScript技巧
我写JavaScript代码已经很久了,都记不起是什么年代开始的了.对于JavaScript这种语言近几年所取得的成就,我感到非常的兴奋:我很幸运也是这些成就的获益者.我写了不少的文章,章节,还有一本 ...
- 修改elasticsearch5,搜索结果最大10000
一:在Linux服务器中执行如下命令(开启es服务) curl -XPUT http://服务器ip:9200/索引名称/_settings -d '{ "index" : { & ...
- Oracle嵌套表
一.介绍 1.定义 嵌套表是表中之表.一个嵌套表是某些行的集合,它在主表中表示为其中的一列.对主表中的每一条记录,嵌套表可以包含多个行.在某种意义上,它是在一个表中存储一对多关系的一种方法. ...
- STL-set and multiset
! ! ! ! set 中的元素总是保持单调递增. set<int> a; set的插入 set没有尾部插入函数push_back(),元素的插入一般使用insert进行动态检索插入. a ...
- Ubuntu 14.04 + xRDP + Xfce 实现Windows远程桌面连接
1. 安装xRDP及vncserver sudo apt-get install xrdp sudo apt-get install vnc4server tightvncserver 2. 安装Xf ...