1. 题目描述
有n个点,求能覆盖这n个点的半径最小的圆的圆心及半径。

2. 基本思路
算法模板http://soft.cs.tsinghua.edu.cn/blog/?q=node/1066定义Di表示相对于P[1]和P[i]组成的最小覆盖圆,如果P[2..i-1]都在这个圆内,那么当前的圆心和半径即为最优解。
如果P[j]不在这个圆内,那么P[j]一定在新的最小覆盖圆的边界上即P[1]、P[j]、P[i]组成的圆。
因为三点可以确定一个圆,因此只需要不断的找到不满足的P[j],进而更新最优解即可。
其实就是三层循环,不断更新最优解。然而,这个算法的期望复杂度是O(n)。这个比较难以理解。

3. 代码

 /* 3007 */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct {
double x, y;
} Point; const double eps = 1e-;
const int maxn = ;
Point P[maxn];
Point o;
double r;
int n; double Length(Point a, Point b) {
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
} double Cross(Point a, Point b, Point c) {
return (c.x-a.x)*(b.y-a.y) - (c.y-a.y)*(b.x-a.x);
} Point Intersect(Point a, Point b, Point c, Point d) {
Point ret = a;
double t = ((a.x - c.x) * (c.y - d.y) - (a.y - c.y) * (c.x - d.x)) /
((a.x - b.x) * (c.y - d.y) - (a.y - b.y) * (c.x - d.x));
ret.x += (b.x - a.x) * t;
ret.y += (b.y - a.y) * t;
return ret;
} Point circumcenter(Point a, Point b, Point c) {
Point ua, ub, va, vb; ua.x = (a.x + b.x) / 2.0;
ua.y = (a.y + b.y) / 2.0;
ub.x = ua.x - a.y + b.y;
ub.y = ua.y + a.x - b.x; va.x = (a.x + c.x) / 2.0;
va.y = (a.y + c.y) / 2.0;
vb.x = va.x - a.y + c.y;
vb.y = va.y + a.x - c.x;
return Intersect(ua, ub, va, vb);
} void min_center() {
o = P[];
r = ; rep(i, , n) {
if (Length(P[i], o)-r > eps) {
o = P[i];
r = ;
rep(j, , i) {
if (Length(P[j], o)-r > eps) {
o.x = (P[i].x + P[j].x) / ;
o.y = (P[i].y + P[j].y) / ;
r = Length(o, P[j]); rep(k, , j) {
if (Length(P[k], o)-r > eps) {
o = circumcenter(P[i], P[j], P[k]);
r = Length(o, P[k]);
}
}
}
}
}
}
} void solve() {
min_center();
printf("%.2lf %.2lf %.2lf\n", o.x, o.y, r);
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (scanf("%d", &n)!=EOF && n) {
rep(i, , n)
scanf("%lf%lf", &P[i].x, &P[i].y);
solve();
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】3007 Buried memory的更多相关文章

  1. 【Linux】Swap与Memory

    背景介绍 Memory指机器物理内存,读写速度低于CPU一个量级,但是高于磁盘不止一个量级.所以,程序和数据如果在内存的话,会有非常快的读写速度.但是,内存的造价是要高于磁盘的,且内存的断电丢失数据也 ...

  2. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  3. hdu 3007 Buried memory 最远点对

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3007 Each person had do something foolish along with ...

  4. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  5. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

  6. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  7. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  8. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  9. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

随机推荐

  1. winform 与 html 交互 简单案例

    本文主要简单的记录winform如何与html文件中的信息如何进行交互,即在winform中加载html界面,从而可以进行相互调用. 1.新建一个winform项目,若要在winform中加载html ...

  2. phpstorm配置取消掉63342

    http://ask.csdn.net/questions/171665

  3. DICOM开源库

    转载于 http://blog.csdn.net/jackmacro/article/details/5850142 Developers used to search for libraries , ...

  4. Python数据结构————二叉查找树的实现

    对于二叉查找树的每个节点Node,它的左子树中所有的关键字都小于Node的关键字,而右子树中的所有关键字都大于Node的关键字. 二叉查找树的平均深度是O(log N). 1.初始化 class Bi ...

  5. butterknife7.0.1使用

    1.官网:http://jakewharton.github.io/butterknife/ Introduction Annotate fields with @Bind and a view ID ...

  6. BitSet

    前几天干了一件比较无聊的事儿——抄了一遍C++ STL bitset的源代码,把不懂的宏定义去掉了,发现(暂时)还能用,嘿嘿. #ifndef BITSET_H #define BITSET_H #i ...

  7. 灵光乍现,lua数据绑定

    MVVM的核心就是数据驱动,数据驱动的核心就是数据绑定. 我一直在思考,如何使用lua做一个数据绑定的功能,仔细思考一下,数据绑定需要做到的功能很简单,就是当一个数据改变时,能主动回调一个或多个函数就 ...

  8. 汽车之家, 比亚迪等成为开源数据库SSDB的用户

    开源的 NoSQL 数据库 SSDB 已经一岁多了! 在这一年中, SSDB 不断被应用在众多业界知名互联网企业, 创业团队的产品中. 最近, 比亚迪汽车也成为 SSDB 的用户, 其将 SSDB 作 ...

  9. [译] ASP.NET 生命周期 – ASP.NET 上下文对象(八)

    使用 HttpResponse 对象 HttpResponse 对象是与 HttpRequest 对象相对应的,用来表示构建中的响应.它当中提供了方法和属性可供我们自定义响应,有一些在使用 MVC 视 ...

  10. sed 常见用法

    sed 1. 移除空白行 sed '/^$/d' file 2. 直接在文本中进行替换 sed 's/pattern/replacement/g' -i file -i[SUFFIX], --in-p ...