题目大意:

给定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. fzu2020( c(n,m)%p,其中n, m, p (1 <= m <= n <= 10^9, m <= 10^4, m < p < 10^9, p是素数) )

    基本的模板题,统计分子分母中p出现的次数,然后求逆元取模. // // main.cpp // fzu2020 // // Created by 陈加寿 on 15/12/27. // Copyrig ...

  2. c# 怎么更改DataTable 中某列的值?

    DataColumns dc = td.Columns["你的列"]; int inx = dc.Ordinal;td.Columns.Remove(dc);dc.DefaultV ...

  3. CoreMotion 加速器陀螺仪

    初始化CoreMotion #import <CoreMotion/CoreMotion.h> CMMotionManager *motionManager = [[CMMotionMan ...

  4. 修改maven的war包生成路径

    因为要配合jenkins,所以控制了war包的生成目录: <plugins> <!--打war包到指定的目录下 --> <plugin> <groupId&g ...

  5. 基本操作——word中怎样同一页中放入多张图片

    可能很多人在放图片时候,碰见这种情况,习惯性的把图片拖进word,发现不能在一页上很工整的排列.很多人包括我刚开始也纳闷,怎么不能一页中放入几张图片呢,缩放也不想.下面分享一个小技巧给有缘人 以我的w ...

  6. jQuery源码分析_工具方法(学习笔记)

    expando:生成唯一JQ字符串(内部使用) noConflict():防止冲突 isReady:DOM是否加载完成(内部) readyWait:等待多少文件的计数器(内部) holdReady() ...

  7. Redis持久化——AOF(二)

    核心知识点: 1.AOF:以独立日志的方式记录写命令,重启时再执行命令.与RDB不同的是解决数据持久化的实时性,可以记录所有写操作. 2.AOF工作流程:写入命令.文件同步.文件重写.文件加载. 3. ...

  8. 3.30课·········Marquee标签

    页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...

  9. 3.15课·········out传值(传址)

    public void Hs(out int a, out int b) { a = 4; b = 6; a = b++;//a=6,b=b+1=7//b先赋值给a,然后b+1 b = ++a;//a ...

  10. C#仿QQ设置界面导航

    效果预览,选择左边标签,右边内容会自动滚动到适当位置 public class AnchorPanel { List<PanelMenu> lst = new List<PanelM ...