HDU 2215 Maple trees
增量法的最小包围圈算法,不会……
#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的更多相关文章
- (hdu step 7.1.5)Maple trees(凸包的最小半径寻找掩护轮)
称号: Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 2215 & hdu 3932(最小覆盖圆)
Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Maple trees(最小覆盖圆)
Maple trees Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 2841 Visible Trees 数论+容斥原理
H - Visible Trees Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 2841 Visible Trees(莫比乌斯反演)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2841 题意:给n*m的矩阵(从(1,1)开始编号)格子,每个格子有一棵树,人站在(0,0)的位置,求可 ...
- HDU p1294 Rooted Trees Problem 解题报告
http://www.cnblogs.com/keam37/p/3639294.html keam所有 转载请注明出处 Problem Description Give you two definit ...
- HDU 2841 Visible Trees(数论)
标题效果:给你个m*n方格,广场格从(1,1)开始. 在树中的每个点,然后让你(0,0)点往下看,问:你能看到几棵树. 解题思路:假设你的视线被后面的树和挡住的话以后在这条线上的树你是都看不见的啊.挡 ...
- hdu 2841 Visible Trees 容斥原理
Visible Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pr ...
- hdu 3015 Disharmony Trees (离散化+树状数组)
Disharmony Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- python 调用hive查询实现类似存储过程
需求:数据仓库中所有表的定义结构保存到新的文件中,保存后类似下面数据,重复的数据只保留7月份即可 ****************ods_log_info*****************lid st ...
- JS图标插件
1.web开发中,有时候需要图标等控件,amcharts可以胜任. amcharts官方网址:http://www.amcharts.com/javascript-charts/
- C - Wooden Sticks
C - Wooden Sticks Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- 5.7.2.1 Math对象
ECMAScript还为保存数学公司公式和信息提供了一个公共位置,即Math对象.与我们在JavaScript直接编写的计算功能相比,Math对象提供的计算功能执行起来要快得多.Math对象中还提供了 ...
- javascript小练习—点击将DIV变成红色(通过for循环遍历)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- JS笔记 入门第三
认识DOM 文档对象模型DOM(Document Object Model)定义访问和处理HTML文档的标准方法.DOM 将HTML文档呈现为带有元素.属性和文本的树结构(节点树) 把上面的代码进行分 ...
- 四轴飞行器1.2.3 STM32F407时钟配置和升级标准库文件
原创文章,欢迎转载,转载请注明出处 这个星期进度比较慢哈,只有周末和晚上下班回来才能做,事件不连续,琐碎的事情又比较多,挺烦的,有多琐碎呢? 1.本人有点小强迫症哈,虽然RTT将文 ...
- C语言迭代求解
date : 2013/8/12 desinger :pengxiaoen 今天看 国外电子信息科学经典教材系列 <电子电路分析与设计> 电子工业出版社的 的19 ...
- 转: mysql create view 创建视图
以下的文章主要是对MySQL视图的描述,其中包括MySQ视图L概述,以及创建MySQL视图-create view与修改MySQL视图--alter view等相关内容的具体描述,以下就是文章的具体内 ...
- Module中引用Module中的Activity时报错了,错误是找不到R文件中的id引用
1.好像库modul和主modul不能有相同名字和layout文件 2.资源文件名冲突导致的