增量法的最小包围圈算法,不会……

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const double EPS = 1e-10;
inline int sgn(double x) { return (x > EPS) - (x < -EPS);}
struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x),y(y) {}
bool operator < (Point a) const { return sgn(x - a.x) < 0 || sgn(x - a.x) == 0 && sgn(y - a.y) < 0;}
bool operator == (Point a) const { return sgn(x - a.x) == 0 && sgn(y - a.y) == 0;}
Point operator + (Point a) const { return Point(x + a.x, y + a.y);}
Point operator - (Point a) const { return Point(x - a.x, y - a.y);}
Point operator * (double p) const { return Point(x * p, y * p);}
Point operator / (double p) const { return Point(x / p, y / p);}
} ;
typedef Point Vec;
inline double crossDet(Vec a, Vec b) { return a.x * b.y - a.y * b.x;}
inline double crossDet(Point o, Point a, Point b) { return crossDet(a - o, b - o);}
inline double dotDet(Vec a, Vec b) { return a.x * b.x + a.y * b.y;}
inline double vecLen(Vec x) { return sqrt(dotDet(x, x));}
inline Point normal(Vec x) { return Point(-x.y, x.x) / vecLen(x);}
Point lineIntersect(Point P, Vec v, Point Q, Vec w) {
Vec u = P - Q;
double t = crossDet(w, u) / crossDet(v, w);
return P + v * t;
}
inline Point getMid(Point a, Point b) { return (a + b) / 2.0;}
struct Circle {
Point c;
double r;
Circle() {}
Circle(Point c, double r) : c(c), r(r) {}
} ; Circle getCircle(Point a, Point b, Point c) {
Vec v1 = b - a, v2 = c - a;
if (sgn(dotDet(b - a, c - a)) <= 0) return Circle(getMid(b, c), vecLen(b - c) / 2.0);
if (sgn(dotDet(a - b, c - b)) <= 0) return Circle(getMid(a, c), vecLen(a - c) / 2.0);
if (sgn(dotDet(a - c, b - c)) <= 0) return Circle(getMid(a, b), vecLen(a - b) / 2.0);
Point ip = lineIntersect(getMid(a, b), normal(v1), getMid(a, c), normal(v2));
return Circle(ip, vecLen(ip - a));
}
int andrew(Point *pt, int n, Point *ch) {
sort(pt, pt + n);
int m = 0;
for (int i = 0; i < n; i++) {
while (m > 1 && sgn(crossDet(ch[m - 2], ch[m - 1], pt[i])) <= 0) m--;
ch[m++] = pt[i];
}
int k = m;
for (int i = n - 2; i >= 0; i--) {
while (m > k && sgn(crossDet(ch[m - 2], ch[m - 1], pt[i])) <= 0) m--;
ch[m++] = pt[i];
}
if (n > 1) m--;
return m;
}
const int N = 555;
Point pt[N], ch[N];
int rnd[N];
void randPoint(Point *pt, int n) {
for (int i = 0; i < n; i++) rnd[i] = (rand() % n + n) % n;
for (int i = 0; i < n; i++) swap(pt[i], pt[rnd[i]]);
}
inline bool inCircle(Point p, Circle C) { return sgn(vecLen(C.c - p) - C.r) <= 0;}
int main() {
int n;
while (cin >> n && n) {
for (int i = 0; i < n; i++) scanf("%lf%lf", &pt[i].x, &pt[i].y);
n = andrew(pt, n, ch);
randPoint(ch, n);
Circle ans = Circle(ch[0], 0.0), tmp;
for (int i = 0; i < n; i++) {
if (inCircle(ch[i], ans)) continue;
ans = Circle(ch[i], 0.0);
for (int j = 0; j < i; j++) {
if (inCircle(ch[j], ans)) continue;
ans = Circle(getMid(ch[i], ch[j]), vecLen(ch[i] - ch[j]) / 2.0);
for (int k = 0; k < j; k++) {
if (inCircle(ch[k], ans)) continue;
ans = getCircle(ch[i], ch[j], ch[k]);
}
}
}
printf("%.2f\n", ans.r + 0.5);
}
return 0;
}

HDU 2215 Maple trees的更多相关文章

  1. (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)

    称号: Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  2. hdu 2215 & hdu 3932(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. Maple trees(最小覆盖圆)

    Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  4. HDU 2841 Visible Trees 数论+容斥原理

    H - Visible Trees Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 2841 Visible Trees(莫比乌斯反演)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2841 题意:给n*m的矩阵(从(1,1)开始编号)格子,每个格子有一棵树,人站在(0,0)的位置,求可 ...

  6. HDU p1294 Rooted Trees Problem 解题报告

    http://www.cnblogs.com/keam37/p/3639294.html keam所有 转载请注明出处 Problem Description Give you two definit ...

  7. HDU 2841 Visible Trees(数论)

    标题效果:给你个m*n方格,广场格从(1,1)开始. 在树中的每个点,然后让你(0,0)点往下看,问:你能看到几棵树. 解题思路:假设你的视线被后面的树和挡住的话以后在这条线上的树你是都看不见的啊.挡 ...

  8. hdu 2841 Visible Trees 容斥原理

    Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Pr ...

  9. hdu 3015 Disharmony Trees (离散化+树状数组)

    Disharmony Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. asp.net 下载文件(图片、word、excel等)

    string filePath = Server.MapPath("~/excel.xlsx"); if (File.Exists(filePath)) { FileStream ...

  2. hosts文件简析

    什么是hosts文件 hosts文件是个什么文件呢?Hosts虽然没有后缀名,其实是个纯文本文件,可以用记事本等文本编辑软件打开.Hosts文件主要用于在本地电脑强制解析域名,Hosts文件里包含映射 ...

  3. 兼容现有jQuery API的轻量级JavaScript库:Zepo

    Zepo是一个JavaScript框架,其特点是兼容现有jQuery API的同时,自身体积十分小:它与jQuery有着类似的API.如果你会jQuery,那么也就会使用Zepto了. $('div' ...

  4. day5_python学习笔记_chapter7_字典

    1. 内建方法fromkeys()创建一个默认字典, 字典中元素具有相同的值,默认为None dict1 = {}.fromkeys(('x', 'y'), -1) 2. 访问字典中的值,  for ...

  5. EditText 双击才能获取点击事件

    在获取EditText点击事件的过程中,发现EditText setOnClickListener事件响应中,只有获取焦点的时候才会响应, 如当焦点在别的控件上时,只能先点击获取焦点,第二次点击才会响 ...

  6. PHP -- 添加注释

    PHP支持3种风格的注释 1.C++风格(//)的注释 这种注释不能出现?>标记,如果开启short_open和asp_tag设置,>和%>同样不能出现在注释中 <?php e ...

  7. jQuery入门第二

    element选择器​ 在文具盒中,有铅笔.钢笔和水彩笔,类似于页面中的<div>.<span>各个元素,虽然同属于一个容器,但有各自的功能,jQuery中可以根据元素名查找元 ...

  8. SQL 时间戳

    一直对时间戳这个概念比较模糊,相信有很多朋友也都会误认为:时间戳是一个时间字段,每次增加数据时,填入当前的时间值.其实这误导了很多朋友. 1.基本概念 时间戳:数据库中自动生成的唯一二进制数字,与时间 ...

  9. 闪存主控IC的作用

    闪存主要是由闪存芯片.主控芯片.晶振.PCB板等部件组成的.其中主控芯片相当于闪存的“灵魂”,它控制着闪存的工作.主控芯片也是处理单元,在里面写入的程序对整个电路做控制.主控IC是把flash跟hos ...

  10. U盘中的闪存白片与黑片

    简单的说,黑片的概念主要用于芯片,白片的概念既用于芯片也用于闪存卡.黑片就是指芯片工厂选出的淘汰的次品,没有打上工厂标和芯片型号的芯片,这样的芯片都经过个种渠道流通到市场上来,现在很多U盘大厂大量的采 ...