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) ...
随机推荐
- <%=id%>是什么意思
<%=% > 这里可以绑定后台的一个PUBLIC变量 <% % > 如果没有等号 可以在里面写C#语句
- JavaScript知识(二)
你要保守你心,胜过保守一切,因为一生的果效,是由心发出的.————O(∩_∩)O... ...O(∩_∩)O...老师因有事下午没来上课,今天就只把中午讲的知识总结一下.由于昨天只是讲了JavaScr ...
- Filemanager 的使用
filemanager的使用包括: 1.创建文件夹 2.删除文件夹 3.写入文件 4.复制文件 5.移动文件 6.删除文件 一.创建文件夹 首先宏的定义一个字符串作为地址的来获取当前的docum ...
- SGU 506.Subsequences Of Substrings
求一个串S有多少子串subS满足s是subS的子序列.len(S)<=100000, len(s)<=100 直接扫一遍... ------------------------------ ...
- Android常用工具类封装---SharedPreferencesUtil
SharedPreferences常用于保存一些简单的数据,如记录用户操作的配置等,使用简单. public class SharedPreferencesUtil { // ...
- C# WINFORM 线程中更新UI
幸好今天是周末,有时间把这个问题记录一下.在多种语言之间切换,发现开发效率降的很低了,开发成本都集中到调式上了,C/C++这些放弃很久了,突然感觉线程这个问题搞的有点烦躁 我这里提到的线程中更新UI, ...
- Qt实现嵌入桌面的半透明窗口 good
这儿用上了前面一文提到的函数findDesktopIconWnd().见: http://mypyg.blog.51cto.com/820446/263349 一.将Qt窗口嵌入到桌面中.声明一个最简 ...
- Springmvc+Spring+Hibernate搭建方法及实例
Springmvc+Spring+Hibernate搭建方法及实例
- 具有 CSA CCM 证明的 SOC 2 可简化 Windows Azure 客户的安全性评估过程
编辑人员注释:本文章由 Windows Azure 产品市场营销总监 Sarah Fender 撰写. 今天,我们宣布 Microsoft 的公共审计师 Deloitte 已经发布了有关 Window ...
- BZOJ 4300 绝世好题(位运算)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4300 [题目大意] 给出一个序列a,求一个子序列b,使得&和不为0 [题解] ...