题目描述

给出N个点,让你画一个最小的包含所有点的圆。

输入输出格式

输入格式:

先给出点的个数N,2<=N<=100000,再给出坐标Xi,Yi.(-10000.0<=xi,yi<=10000.0)

输出格式:

输出圆的半径,及圆心的坐标,保留10位小数

输入输出样例

输入样例#1:
复制

6
8.0 9.0
4.0 7.5
1.0 2.0
5.1 8.7
9.0 2.0
4.5 1.0
输出样例#1: 复制

5.0000000000
5.0000000000 5.0000000000

说明

5.00 5.00 5.0

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 400005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-11
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii; inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ struct node {
double x, y;
}pt[maxn]; node o;
int n;
double r; double dis(node a, node b) {
return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
} void dt(node p1, node p2, node p3) {
double a, b, c, d, e, f;
a = p2.y - p1.y;
b = p3.y - p1.y;
c = p2.x - p1.x;
d = p3.x - p1.x;
f = p3.x*p3.x + p3.y*p3.y - p1.x*p1.x - p1.y*p1.y;
e = p2.x*p2.x + p2.y*p2.y - p1.x*p1.x - p1.y*p1.y;
o.x = (a*f - b * e) / (2 * a*d - 2 * b*c);
o.y = (d*e - c * f) / (2 * a*d - 2 * b*c);
r = dis(o, p1);
} int main() {
// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
rdint(n);
for (int i = 1; i <= n; i++) {
rdlf(pt[i].x); rdlf(pt[i].y);
}
random_shuffle(pt + 1, pt + 1 + n);
o = pt[1]; r = 0;
for (int i = 2; i <= n; i++) {
if (dis(pt[i], o) > r + eps) {
o = pt[i]; r = 0;
for (int j = 1; j <= i - 1; j++) {
if (dis(o, pt[j]) > r + eps) {
o.x = (pt[i].x + pt[j].x) / 2.0;
o.y = (pt[i].y + pt[j].y) / 2.0;
r = dis(o, pt[j]);
for (int k = 1; k <= j - 1; k++) {
if (dis(o, pt[k]) > r + eps) {
dt(pt[i], pt[j], pt[k]);
}
}
}
}
}
}
printf("%.10lf\n%.10lf %.10lf", 1.0*r, o.x, o.y);
return 0;
}

最小圆覆盖 [模板] BZOJ 1337&1336的更多相关文章

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

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

  2. BZOJ1336 Balkan2002 Alien最小圆覆盖 【随机增量法】*

    BZOJ1336 Balkan2002 Alien最小圆覆盖 Description 给出N个点,让你画一个最小的包含所有点的圆. Input 先给出点的个数N,2<=N<=100000, ...

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

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

  4. Bzoj 1336&1337 Alien最小圆覆盖

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special Judge Submit: 1473  ...

  5. [BZOJ 1336] [Balkan2002] Alien最小圆覆盖 【随机增量法】

    题目链接:BZOJ - 1336 题目分析 最小圆覆盖有一个算法叫做随机增量法,看起来复杂度像是 O(n^3) ,但是可以证明其实平均是 O(n) 的,至于为什么我不知道= = 为什么是随机呢?因为算 ...

  6. bzoj 1336 最小圆覆盖

    最小圆覆盖 问题:给定平面上的一个点集,求半径最小的一个圆,使得点集中的点都在其内部或上面. 随机增量算法: 定义:点集A的最小圆覆盖是Circle(A) 定理:如果Circle(A)=C1,且a不被 ...

  7. 【BZOJ】1336: [Balkan2002]Alien最小圆覆盖

    题解 我们先把所有点random_shuffle一下 然后对前i - 1个点计算一个最小圆覆盖,然后第i个点如果不在这个圆里,那么我们把这个点当成一个新的点,作为圆心,半径为0 从头枚举1 - i - ...

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

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

  9. 【BZOJ-1336&1337】Alie最小圆覆盖 最小圆覆盖(随机增量法)

    1336: [Balkan2002]Alien最小圆覆盖 Time Limit: 1 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 1573   ...

随机推荐

  1. java定时任务调度工具Timer与Quartz的区别

    Timer与Quartz的区别有三点: 1.出身不同:Timer由jdk直接提供,调用方式简单粗暴,不需要其它jar包支持.Quartz并非jdk自带,需要引入相应的jar包 2.能力区别:主要体现在 ...

  2. saltstack系列(二)——zmq应答模式

    python zeromq介绍 1.ZeroMQ并不是一个对socket的封装,不能用它去实现已有的网络协议. 2.有自己的模式,不同于更底层的点对点通讯模式. 3.有比tcp协议更高一级的协议(当然 ...

  3. 手动去除uTorrent中广告的步骤(V3.4.9依然有效)

    1.开打utorrent,依次点击选项->设置->高级. 在“高级”界面中,你会看到“过滤器”,在“过滤器”右侧的框中输入“offers”. 这时会在下面框中看到“offers.left_ ...

  4. get-task-allow有什么用

    [failed to get the task for process问题] A: Why am I getting "Error launching remote program: fai ...

  5. oracle级联更新与级联删除

    Oracle级联删除:可以使用外键约束来实现,建立表的主外键关系,给列设置级联删除.如下: ——创建了CLASS表,并设置ID字段为主键. -- Create tablecreate table CL ...

  6. mysql视图总结

    http://www.2cto.com/database/201508/427083.html 一. 视图概述 视图是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据. ...

  7. HTTP防盗链与反防盗链

    HTTP防盗链 通过上一次,我没对HTTP请求不再那么陌生了.防盗链无非就是别人来请求自己网站的信息,用于其他网站,那么如果我们能识别请求是来自那个网站,如果是外网,那么就重定向等其他处理.但在web ...

  8. django: django rest framework 分页

    django: django rest framework 分页 2018年06月22日 13:41:43 linux_player_c 阅读数:665更多 所属专栏: django 实战   版权声 ...

  9. Django rest_framework----认证,权限,频率组件

    认证 from rest_framework.authentication import BaseAuthentication from rest_framework.exceptions impor ...

  10. 远程访问Function时报错Remote table-valued function calls are not allowed.

    开始是这样调用的:select * from [LinkedServer].[db name].dbo.[function name](param1, param2) 原因: Only table-v ...