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) ...
随机推荐
- 用VIM删除空行
从网上找了一个 :g/^s*$/d 开始用的挺好,后来遇到一种空格开头的空行,就不好用了. MSDN上说正则匹配空行用/^\s*$/,就试着把上面的命令改为: :g/^\s*$/d 就可以了. 用的操 ...
- Java DecimalFormat 格式化数字
我们经常要将数字进行格式化,比如取2位小数,这是最常见的.Java 提供 DecimalFormat 类,帮你用最快的速度将数字格式化为你需要的样子.下面是一个例子: importjava.text. ...
- CocoaPods 出现 OTHER_LDFLAGS 错误的解决方法
CocoaPods 出现 OTHER_LDFLAGS 错误的解决方法 在一些项目中运行 pod install 后经常会出现如下错误 [!] The target `项目名 [Debug]` over ...
- c++读取文件内容并保存到二维数组
每行数据最后需要Tab处理 #include <iostream> #include <fstream> #include <string> using names ...
- [LeetCode]题解(python):142-Linked List Cycle II
题目来源: https://leetcode.com/problems/linked-list-cycle-ii/ 题意分析: 给定一个链表,如果链表有环,返回环的起始位置,否则返回NULL.要求常量 ...
- Arduino Micro USB库
USBCore.cpp #define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_co ...
- IOS 物理引擎
来自IOS7 by tutorials 下面是个人的一点翻译总结 1,首先在初始化方法李画一个方块 UIView* square = [[UIView alloc] initWithFrame: ...
- 一維條碼 EAN13 的編碼方式
何謂 EAN-13碼 ? ▲ 國家代號(3位數) 中華民國的國家代號為471. ▲ 廠商代號(6位數) 由本會核發給廠商6位數的廠商代號. ▲ 商品代號(3位數) 由廠商自行編定,按一物一號的原則,不 ...
- Qt 不规则窗体的实现(构造函数里setPaletteBackgroundPixmap后设置setMask)
Skin(表皮) 是制作比较酷的软件界面的有利工具. 一个软件可以同时使用多种Skin 以取得不同的外观, 使同一个软件有截然不同的风格. 用户可以根据自己的喜好选择 不同的风格. 本节介绍使用 Qt ...
- sublime的20个插件
SublimeText是一款非常精巧的文本编辑器,适合编写代码.做笔记.写文章.它用户界面十分整洁,功能非同凡响,性能快得出奇.这些非常棒的特性 包括任意跳转(Goto Anything).多重选择( ...