题目大意:

给定n个点,求面积最小的园覆盖所有点.其中\(n \leq 10^6\)

题解:

恩。。。

刚拿到这道题的时候...

什么???最小圆覆盖不是\(O(n^3)\)的随机增量算法吗?????

\(10^6\)又是个什么鬼?????????

然后去%了popoqqq大爷的题解...原来这道题数据是随机的啊。。。

随机数据有一个性质,在凸包上的点不超过\(logn\)

所以我们求凸包然后在上面跑随机增量算法即可

#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 1000010;
const double eps = 1e-9;
inline int dcmp(const double &x){
if(x < eps && x > -eps) return 0;
return x > 0 ? 1 : -1;
}
struct Point{
double x,y;
Point(const double &a = 0,const double &b = 0){x=a;y=b;}
void print(){
printf("Point : (%lf,%lf)\n",x,y);
}
};
typedef Point Vector;
inline Vector operator + (const Vector &a,const Vector &b){
return Vector(a.x+b.x,a.y+b.y);
}
inline Vector operator - (const Vector &a,const Vector &b){
return Vector(a.x-b.x,a.y-b.y);
}
inline Vector operator / (const Vector &a,const double &b){
return Vector(a.x/b,a.y/b);
}
inline bool operator < (const Point &a,const Point &b){
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
inline double operator * (const Vector &a,const Vector &b){
return a.x*b.x + a.y*b.y;
}
inline double cross(const Vector &a,const Vector &b){
return a.x*b.y - a.y*b.x;
}
inline double sqr(const double &x){
return x*x;
}
inline double dis(const Point &a,const Point &b){
return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}
inline Point getPoint(const Point &p0,const Point &p1,const Point &p2){
double a1 = p1.x - p0.x,b1 = p1.y - p0.y,c1 = (a1*a1 + b1*b1)/2.0;
double a2 = p2.x - p0.x,b2 = p2.y - p0.y,c2 = (a2*a2 + b2*b2)/2.0;
double d = a1*b2 - a2*b1;
return Point(p0.x+(c1*b2-c2*b1)/d,p0.y+(a1*c2-a2*c1)/d);
}
Point o;double r;
inline bool in_cir(const Point &p){
return dcmp(dis(p,o) - r) <= 0;
}
Point p[maxn];int n;
inline void getMinCir(){
o = Point(0,0);r = 0;
for(int i=2;i<=n;++i){
if(!in_cir(p[i])){ o = p[i];r = 0;
for(int j=1;j<i;++j){
if(!in_cir(p[j])){o = (p[i]+p[j])/2.0;r = dis(p[i],o);
for(int k=1;k<j;++k){
if(!in_cir(p[k])){
o = getPoint(p[i],p[j],p[k]);
r = dis(p[i],o);
}
}
}
}
}
}return;
}
Point ch[maxn];int m;
inline void convex(){
sort(p+1,p+n+1);m = 0;
for(int i=1;i<=n;++i){
while(m > 1 && cross(ch[m] - ch[m-1],p[i] - ch[m]) <= 0) -- m;
ch[++m] = p[i];
}int k = m;
for(int i=n-1;i>=1;--i){
while(m > k && cross(ch[m] - ch[m-1],p[i] - ch[m]) <= 0) -- m;
ch[++m] = p[i];
}if(n > 1) -- m;
swap(n,m);swap(p,ch);
}
int main(){
read(n);
for(int i=1;i<=n;++i){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
convex();getMinCir();
printf("%.2lf %.2lf %.2lf\n",o.x,o.y,r);
getchar();getchar();
return 0;
}

bzoj 2823: [AHOI2012]信号塔 最小圆覆盖的更多相关文章

  1. BZOJ.2823.[AHOI2012]信号塔(最小圆覆盖 随机增量法)

    BZOJ 洛谷 一个经典的随机增量法,具体可以看这里,只记一下大体流程. 一个定理:如果一个点\(p\)不在点集\(S\)的最小覆盖圆内,那么它一定在\(S\bigcup p\)的最小覆盖圆上. 所以 ...

  2. 2018.07.04 BZOJ 2823: AHOI2012信号塔(最小圆覆盖)

    2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MB Description 在野外训练中,为了确保每位参加集训的成员安全,实时的掌握 ...

  3. AHOI2012 信号塔 | 最小圆覆盖模板

    题目链接:戳我 最小圆覆盖. 1.枚举第一个点,考虑当前圆是否包含了这个点,如果没有,则把圆变成以这个点为圆心,半径为0的圆. 2.枚举第二个点,考虑圆是否包含了这个点,如果没有,则把圆变成以这两个点 ...

  4. BZOJ 2823: [AHOI2012]信号塔

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2823 随机增量法.不断加点维护圆,主要是三点共圆那里打得烦(其实也就是个两中垂线求交点+联立方 ...

  5. 【BZOJ】2823: [AHOI2012]信号塔

    题意 给\(n\)个点,求一个能覆盖所有点的面积最小的圆.(\(n \le 50000\)) 分析 随机增量法 题解 理论上\(O(n^3)\)暴力,实际上加上随机化后期望是\(O(n)\)的. 算法 ...

  6. bzoj2823[AHOI2012]信号塔

    2823: [AHOI2012]信号塔 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1190  Solved: 545[Submit][Status ...

  7. 【BZOJ2823】[AHOI2012]信号塔(最小圆覆盖)

    [BZOJ2823][AHOI2012]信号塔(最小圆覆盖) 题面 BZOJ 洛谷 相同的题: BZOJ1 BZOJ2 洛谷 题解 模板题... #include<iostream> #i ...

  8. BZOJ2823 [AHOI2012]信号塔 【最小圆覆盖】

    题目链接 BZOJ2823 题解 最小圆覆盖模板 都懒得再写一次 #include<iostream> #include<cstdio> #include<cmath&g ...

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

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

随机推荐

  1. gridControl使用集锦

    1.grid控件默认选择一行时,focused的cell并不是蓝色的,而是白色的 要想实现一次选择一行全都是蓝色的只要改一个属性就可以了 this.gridView1.OptionsSelection ...

  2. 如何使用subversion管理iOS源代码

    本文转载至 http://2009315319.blog.51cto.com/701759/819216 使用subversion管理iOS源代码 1.安装和配置subversion服务器 在wind ...

  3. thinkphp自动验证无效的问题

    新手入门thinkphp,试用自动验证表单输入数据功能,却发现怎么都不能调用自动验证,自动验证无效,原因竟是一个小细节的疏忽,学习一定要细心啊! Action方法: IndexAction下的adds ...

  4. os模块,sys模块

    # os模块 # os模块是与操作系统交互的一个接口 ''' 和工作目录相关: os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径(在什么地方执行就是那个文件的路径) os ...

  5. Dbvisualizer 连接oracle数据库

    软件及驱动下载: 链接:https://pan.baidu.com/s/1OhuRDCd6FDi21NyCEdN2dA 密码:0rtp 软件破解办法: 1. 找到<C:\Program File ...

  6. hive常规配置及常用命令使用

    hive 常用的几种shell交互方式 查看hive命令帮助:bin/hive -help [hd@hadoop-senior hive]$ bin/hive -help usage: hive -d ...

  7. Coreos 安装及配置

    Coreos 安装及配置 本文由Vikings(http://www.cnblogs.com/vikings-blog/) 原创,转载请标明.谢谢! 目前国内使用coreos的场景还不多,搜索core ...

  8. 事件监听机制——列出指定目录内容、添加Dialog对话框

    事件监听机制理解与Dialog练习 利用Java语言,仿照我的电脑目录进行打开目录,输入文件路径,查看该路径下所有的文件,设置两个文本框,一个转到按钮,当点击转到按钮时,查看路径是否正确,若正确在第二 ...

  9. P2163 [SHOI2007]园丁的烦恼

    题目 P2163 [SHOI2007]园丁的烦恼 做法 关于拆点,要真想拆直接全部用树状数组水过不就好了 做这题我们练一下\(cdq\)分治 左下角\((x1,y1)\)右上角\((x2,y2)\), ...

  10. css 行内元素 块元素 替换元素 非替换元素 以及这些元素的width height margin padding 特性

    一.各种元素的width height margin padding 特性(具体css元素的分来参看二) 1.块级元素 width. height. margin的四个方向. padding的四个方向 ...