BZOJ 2823: [AHOI2012]信号塔
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2823
随机增量法。不断加点维护圆,主要是三点共圆那里打得烦(其实也就是个两中垂线求交点+联立方程求交点而已TAT。。
#include<cstring>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 1000009
#define eps 1e-6
using namespace std;
typedef unsigned long long ll;
struct P{double x,y;
}a[maxn],o;
double r;
int n;
int read(){
int x=,f=; char ch=getchar();
while (!isdigit(ch)){
if (ch=='-') f=-; ch=getchar();
}
while (isdigit(ch)){
x=x*+ch-''; ch=getchar();
}
return x*f;
}
P get2(P a,P b){
P tmp;
tmp.x=(a.x+b.x)/; tmp.y=(a.y+b.y)/;
return tmp;
}
double sqr(double x){
return x*x;
}
double dis(P a,P b){
return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}
P cross(double a1,double a2,double b1,double b2,double c1,double c2){
P tmp;
tmp.x=(c2*b1-c1*b2)/(a1*b2-a2*b1); tmp.y=(c2*a1-c1*a2)/(b1*a2-b2*a1);
return tmp;
}
P get3(P a,P b,P c){
P tmp;
double a1=b.x-a.x,b1=b.y-a.y,c1=(sqr(a.y)-sqr(b.y)+sqr(a.x)-sqr(b.x))/;
double a2=c.x-a.x,b2=c.y-a.y,c2=(sqr(a.x)+sqr(a.y)-sqr(c.x)-sqr(c.y))/;
return tmp=cross(a1,a2,b1,b2,c1,c2);
}
int cmp(double x){
if (fabs(x)<eps) return ;
if (x>) return ;
return -;
}
int main(){
n=read();
rep(i,,n){
scanf("%lf%lf",&a[i].x,&a[i].y);
}
int x,y;
rep(i,,n) {
x=rand()%n+; y=rand()%n+;
swap(a[x],a[y]);
}
o=a[]; r=;
rep(i,,n){
if (cmp(dis(a[i],o)-r)<) continue;
o=a[i]; r=;
rep(j,,i-){
if (cmp(dis(a[j],o)-r)<) continue;
o=get2(a[i],a[j]); r=dis(a[j],o);
rep(k,,j-) {
if (cmp(dis(a[k],o)-r)<) continue;
o=get3(a[i],a[j],a[k]); r=dis(a[k],o);
}
}
}
printf("%.2lf %.2lf ",o.x,o.y);
printf("%.2lf\n",r);
return ;
}
BZOJ 2823: [AHOI2012]信号塔的更多相关文章
- 2018.07.04 BZOJ 2823: AHOI2012信号塔(最小圆覆盖)
2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MB Description 在野外训练中,为了确保每位参加集训的成员安全,实时的掌握 ...
- BZOJ.2823.[AHOI2012]信号塔(最小圆覆盖 随机增量法)
BZOJ 洛谷 一个经典的随机增量法,具体可以看这里,只记一下大体流程. 一个定理:如果一个点\(p\)不在点集\(S\)的最小覆盖圆内,那么它一定在\(S\bigcup p\)的最小覆盖圆上. 所以 ...
- bzoj 2823: [AHOI2012]信号塔 最小圆覆盖
题目大意: 给定n个点,求面积最小的园覆盖所有点.其中\(n \leq 10^6\) 题解: 恩... 刚拿到这道题的时候... 什么???最小圆覆盖不是\(O(n^3)\)的随机增量算法吗????? ...
- 【BZOJ】2823: [AHOI2012]信号塔
题意 给\(n\)个点,求一个能覆盖所有点的面积最小的圆.(\(n \le 50000\)) 分析 随机增量法 题解 理论上\(O(n^3)\)暴力,实际上加上随机化后期望是\(O(n)\)的. 算法 ...
- bzoj2823[AHOI2012]信号塔
2823: [AHOI2012]信号塔 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1190 Solved: 545[Submit][Status ...
- 【BZOJ2823】[AHOI2012]信号塔(最小圆覆盖)
[BZOJ2823][AHOI2012]信号塔(最小圆覆盖) 题面 BZOJ 洛谷 相同的题: BZOJ1 BZOJ2 洛谷 题解 模板题... #include<iostream> #i ...
- 【bzoj2823】 AHOI2012—信号塔
http://www.lydsy.com/JudgeOnline/problem.php?id=2823 (题目链接) 题意 求最小圆覆盖 Solution 关于最小圆覆盖的做法,论文里面都有.其实真 ...
- (bzoj1337 || 洛谷P1742 最小圆覆盖 )|| (bzoj2823 || 洛谷P2533 [AHOI2012]信号塔)
bzoj1337 洛谷P1742 用随机增量法.讲解:https://blog.csdn.net/jokerwyt/article/details/79221345 设点集A的最小覆盖圆为g(A) 可 ...
- AHOI2012 信号塔 | 最小圆覆盖模板
题目链接:戳我 最小圆覆盖. 1.枚举第一个点,考虑当前圆是否包含了这个点,如果没有,则把圆变成以这个点为圆心,半径为0的圆. 2.枚举第二个点,考虑圆是否包含了这个点,如果没有,则把圆变成以这两个点 ...
随机推荐
- go实例之函数
1.可变参数 示例代码如下: package main import "fmt" // Here's a function that will take an arbitrary ...
- Cat 跨线程之 TaggedTransaction 用法和原理分析
代码 package com.dianping.cat.message.internal; import com.dianping.cat.Cat; import com.dianping.cat.m ...
- 模板引擎(smarty)知识点总结II
今天咱们继续来学习smarty!!! 知识点1:对于三种变量 常量的引用 有哪三种变量?a.assign赋值 b.系统保留变量(包括:$smarty.get,$smarty.post,$smarty. ...
- /sbin/nologin 和 /bin/false 的区别
/bin/false是最严格的禁止login选项,一切服务都不能用,而/sbin/nologin只是不允许系统login,可以使用其他ftp等服务 如果想要用false在禁止login的同时允许ftp ...
- 基于编辑距离来判断词语相似度方法(scala版)
词语相似性比较,最容易想到的就是编辑距离,也叫做Levenshtein Distance算法.在Python中是有现成的模块可以帮助做这个的,不过代码也很简单,我这边就用scala实现了一版. 编辑距 ...
- Ubuntu 16.04 升级 PHP 版本至 7.1
安装swoole扩展,怎么安装到7.0下去了,我本来编译的版本是7.19版本,但是没吃 升级步骤 $ sudo add-apt-repository ppa:ondrej/php $ sudo apt ...
- 解决 react-router / react-router-dom v4 history不能访问的问题
今天我把react-router 升级了一下, 在使用react-router-dom 是,子组件使用this.props.history 找不到了,看看官方文档,找了半天也没找到,因为我是在异步执行 ...
- golang 多维数组
具体的题目如下:(就是将多维数组的行列互换) A multi-dimensional array is an array of arrays. 2-dimensional arrays are the ...
- CS:APP3e 深入理解计算机系统_3e MallocLab实验
详细的题目要求和资源可以到 http://csapp.cs.cmu.edu/3e/labs.html 或者 http://www.cs.cmu.edu/~./213/schedule.html 获取. ...
- select超链接跳转A
客户端页面 实现 下拉菜单 跳转链接 如图 遂使用 select option来展现.开始想到添加 a标签,结果,不行.渲染不出来 搜索查询得知 如下方法实现 ================== & ...