题目描述

给出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. Educational Codeforces Round 45 (Rated for Div. 2)

    A bracket sequence is a string containing only characters "(" and ")". A regular ...

  2. ansible基本使用

    ansible介绍 基础概念 ansible是个配置管理工具,可以批量处理一些任务.ansible只需要依赖ssh即可使用,而不需要在受管主机上安装客户端工具. ansible具有幂等性,即以结果为导 ...

  3. 一篇文章让你了解并掌握memcached

    第一章 memcached简介 1.1为什么引入memcached 随着数据量的增大,访问的集中,REBMS负担加重,数据库响应恶化. Memcached是高性能的分布式内存缓存服务器,目的是通过缓存 ...

  4. Idea的基本介绍

    Idea的基本介绍 Idea一般是作为一个Java和Scala的开发工具来使用的,它的使用方法和Eclipse有一些不同,这里记录以下一些基本点. 1.创建项目 创建一个新项目的时候,用户必须选择一个 ...

  5. errant-transactions

    https://www.percona.com/blog/2015/12/02/gtid-failover-with-mysqlslavetrx-fix-errant-transactions/ 使用 ...

  6. (转)Mac下MySql安装经历(含安装错误排查、卸载多种折腾)

    在安装mysql的时候,活活折腾我两天.结果终于被我折腾成功了……一开始我就放了个错误:我下了32位版本的mysql:mysql-5.5.8-osx10.6-x86.dmg 须知在mac下装的是64位 ...

  7. iOS静态库的制作与引用

    [iOS静态库的制作与引用] 1.Configuring Exported Headers To configure which headers are exported to clients, se ...

  8. 【原创】3. MYSQL++ Query类型与SQL语句执行过程(非template与SSQLS版本)

    我们可以通过使用mysqlpp:: Query来进行SQL语句的增删改查. 首先来看一下mysqlpp::Query的一些最简单的调用, conn.connect(mysqlpp::examples: ...

  9. vs2017不是完全支持c99

    1.比如c99里面有一个特性, int count[]={0,[5]=7,9,10} 这种在VS2017里面是编译不通过的.; 2.c99有一个变长数组的概念(VLA),但是vs2017不支持.

  10. PHP防止木马攻击的措施

    防止跳出web目录 只允许你的PHP脚本在web目录里操作,针对Apache,还可以修改httpd.conf文件限制PHP操作路径. 例如:php_admin_value  open_basedir( ...