http://www.lydsy.com/JudgeOnline/problem.php?id=2823 (题目链接)

题意

  求最小圆覆盖

Solution

  关于最小圆覆盖的做法,论文里面都有。其实真正麻烦的是求三角形的外心。

代码

// bzoj2823
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<vector>
#define eps 1e-10
#define inf 2147483640
#define LL long long
#define free(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
using namespace std;
inline LL getint() {
LL x=0,f=1;char ch=getchar();
while (ch>'9' || ch<'0') {if (ch=='-') f=-1;ch=getchar();}
while (ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
return x*f;
} const int maxn=1000010;
struct point {double x,y;}p[maxn];
int n; double dis(point a,point b) {
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
point center(point a,point b,point c) {
double a1=b.x-a.x,b1=b.y-a.y,c1=(a1*a1+b1*b1)/2;
double a2=c.x-a.x,b2=c.y-a.y,c2=(a2*a2+b2*b2)/2;
double d=a1*b2-a2*b1;
return (point){a.x+(c1*b2-c2*b1)/d,a.y+(a1*c2-a2*c1)/d};
}
int main() {
scanf("%d",&n);
for (int i=1;i<=n;i++) {scanf("%lf%lf",&p[i].x,&p[i].y);swap(p[i],p[rand()%i+1]);}
point c=p[1];double r=0;
for (int i=2;i<=n;i++) {
if (dis(c,p[i])<=r+eps) continue;
c=p[i];r=0;
for (int j=1;j<i;j++) {
if (dis(c,p[j])<=r+eps) continue;
c.x=(p[i].x+p[j].x)/2;
c.y=(p[i].y+p[j].y)/2;
r=dis(c,p[j]);
for (int k=1;k<j;k++) {
if (dis(c,p[k])<=r+eps) continue;
c=center(p[i],p[j],p[k]);
r=dis(p[k],c);
}
}
}
printf("%.2f %.2f %.2f",c.x,c.y,r);
return 0;
}

  

【bzoj2823】 AHOI2012—信号塔的更多相关文章

  1. bzoj2823[AHOI2012]信号塔

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

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

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

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

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

  4. [日常摸鱼]bzoj2823 [AHOI2012]信号塔

    题意:$n$个点,求最小圆覆盖,$n \leq 5e5$ 这题数据是随机的hhh 我们可以先求出凸包然后对凸包上的点求最小圆覆盖-(不过直接求应该也行?) 反正随便写好像都能过- #include&l ...

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

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

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

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

  7. (bzoj1337 || 洛谷P1742 最小圆覆盖 )|| (bzoj2823 || 洛谷P2533 [AHOI2012]信号塔)

    bzoj1337 洛谷P1742 用随机增量法.讲解:https://blog.csdn.net/jokerwyt/article/details/79221345 设点集A的最小覆盖圆为g(A) 可 ...

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

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

  9. BZOJ 2823: [AHOI2012]信号塔

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

随机推荐

  1. 第一次使用Android Studio时你应该知道的一切配置(二):新建一个属于自己的工程并安装Genymotion模拟器

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  2. Enem 实用方法

    前言 在项目中的多处使用到了枚举,比如:道具种类(PowerupType) 游戏任务(MissionType),记录一下有关枚举的一些方法 枚举 public enum MissionType { R ...

  3. java 16 -3 Vector的特有功能

    /* * Vector的特有功能: * 1:添加功能 替代 * public void addElement(Object obj) -- add() * 2:获取功能 * public Object ...

  4. Corotational 模型代码

    今天看了Corotational模型的代码. 在Vega中,获得模型内力的方法是先构造一个ForceModel对象,再调用其对应方法. 对于Corotational模型,构造的流程为: 构造Corot ...

  5. bean的作用域

    bean的作用域为singleton,spring容器中只存在一个bean的实例,所有对该bean的请求只返回同一个bean实例. 当bean的作用域为prototype时,每一次对bean的请求,都 ...

  6. f2fs解析(七)node管理器中的 free_nid 结构体

    除了node_info之外, node管理器中还有还有个重要的数据结构: struct free_nid { struct list_head list; /* for free node id li ...

  7. 003医疗项目-关于<context:property-placeholder location="classpath:db.properties"/>的问题

    项目结构如下:

  8. 调用Oracle存储过程并获取out参数值

    原文: http://tech.it168.com/oldarticle/2006-04-02/200604021512359.shtml http://www.cnblogs.com/m-cnblo ...

  9. svn命令行修改已提交的版本备注

    svn命令行修改已提交的版本备注 参考文章: stackoverflow.com/questions/304383/how-do-i-edit-a-log-message-that-i-already ...

  10. benchmark

    redis benchmark How many requests per second can I get out of Redis? Using New Relic to Understand R ...