【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 ...
随机推荐
- Java 9 新特性快速预览
原文出处:wangwenjun69 Java 8 已经出来三年多的时间了,原本计划2016年七月份release Java 9,但是基于种种原因,Java 9 被推迟到了2017年的3月份,本人也在O ...
- caffe rpn layer 中的 reshape layer
Reshape层:(改变blob的形状,N,C,W,H) layer { name: "reshape" type: "Reshape" bottom: &qu ...
- Linux QT数据库之登录注册
视频链接:https://www.bilibili.com/video/av11673511/ main.cpp #include <QSqlDatabase> #include < ...
- 20145209 2016-2017-2 《Java程序设计》第7周学习总结
20145209 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 read()每次读入一个字节. eg:short2个字节,2=0x0201,读入后要0x & ...
- [洛谷P1228]地毯填补问题 题解(分治)
Description 相传在一个古老的阿拉伯国家里,有一座宫殿.宫殿里有个四四方方的格子迷宫,国王选择驸马的方法非常特殊,也非常简单:公主就站在其中一个方格子上,只要谁能用地毯将除公主站立的地方外的 ...
- 天梯 1083 Cantor表
解题报告:发现规律就可以了,斜着看,第一条线上有1个,第二条线上有2个,....然后求出等差数列前n项和,求出N在第几条线上,然后就看N是在这条线上的第几个就可以了. #include<cstd ...
- URAL 1416 Confidential (最小生成树+次小生成树)
Description Zaphod Beeblebrox - President of the Imperial Galactic Government. And by chance he is a ...
- PHP返回Json数据函数封装
/** * 返回Json数据 * @param int $code * @param string $message * @param array $data * @return string */ ...
- Cesium entity click
var url = 'http://202.107.245.51:81/user/dev/api/v2/sql?rows_per_page=40&page=0&sort_order=a ...
- Linux input子系统学习总结(一)---- 三个重要的结构体
一 . 总体架构 图 上层是图形界面和应用程序,通过监听设备节点,获取用户相应的输入事件,根据输入事件来做出相应的反应:eventX (X从0开始)表示 按键事件,mice 表示鼠标事件 Input ...