poj 2187 旋转卡壳求最远点对的平方
来源:互联网 发布:金融大数据应该学什么 编辑:程序博客网 时间:2024/05/16 06:43
今天学了下旋转卡壳,感觉还好...
先求凸包然后旋转卡壳就行了。
据说这题的数据可以直接暴力凸包求距离就行了,数据太水 = =
代码:
/** Author: illuz <iilluzen[at]gmail.com>* Blog: http://blog.csdn.net/hcbbt* File: poj2187.cpp* Create Date: 2013-11-23 09:34:38* Descripton: rotating calipers */#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;#define sqr(a) ((a) * (a))const int MAXN = 50000;const double PI = acos(-1.0);const int INF = 0x7fffffff;struct Point {double x;double y;Point() {};Point(double tx, double ty) {x = tx;y = ty;}Point operator-(const Point &b) const {return Point(x - b.x, y - b.y);}Point operator+(const Point &b) const {return Point(x + b.x, y + b.y); }Point operator*(const double &k) const {return Point(x * k, y * k);}double operator*(const Point &b) const {// 点积return x * b.y + y * b.x;}double operator^(const Point &b) const {// 叉积return x * b.y - y * b.x;}friend bool operator < (const Point &l, const Point &r) {return l.y < r.y || (l.y == r.y && l.x < r.x);}} p[MAXN], ch[MAXN * 2];// p, point ch, convex hulldouble dis(const Point &a, const Point &b) {return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));}double ddis(const Point &a, const Point &b) {return sqr(a.x - b.x) + sqr(a.y - b.y);}double mult(const Point &a, const Point &b, const Point &o) {return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);}int Graham(Point p[], int n, Point res[]) {int top = 1;sort(p, p + n);if (n == 0) return 0;res[0] = p[0];if (n == 1) return 1;res[1] = p[1];if (n == 2) return 2;res[2] = p[2];for (int i = 2; i < n; i++) {while (top && (mult(p[i], res[top], res[top - 1]) >= 0))top--;res[++top] = p[i];}int len = top;res[++top] = p[n - 2];for (int i = n - 3; i >= 0; i--) {while (top != len && (mult(p[i], res[top], res[top - 1]) >= 0))top--;res[++top] = p[i];}return top;}double rotating_calipers(Point *p, int n) {n = Graham(p, n, ch);int q = 1;double ans = 0;ch[n] = ch[0];for (int p = 0; p < n; p++) {while (mult(ch[p + 1], ch[q + 1], ch[p]) > mult(ch[p + 1], ch[q], ch[p]))q = (q + 1) % n;ans = max(ans, max(ddis(ch[p], ch[q]), ddis(ch[p + 1], ch[q + 1])));}return ans;}int main() {int n;scanf("%d", &n);for (int i = 0; i < n; i++)scanf("%lf%lf", &p[i].x, &p[i].y);printf("%.0f\n", rotating_calipers(p, n));return 0;}
- poj 2187 旋转卡壳求最远点对的平方
- 旋转卡壳 求最远点对
- poj 2187 Beauty Contest(旋转卡壳求最远点对)
- poj 2187 求平面最远点对 快速凸包 旋转卡壳
- 【凸包】poj 2187 Beauty Contest (旋转卡壳求平面最远点对)
- POJ 2187 Beauty Contest (求最远点对,凸包+旋转卡壳)
- poj 2187 求凸包最远点对--旋转卡壳
- poj 2187 旋转卡壳(平面上最远点对)
- POJ 2187 Beauty Contest 最远点对(旋转卡壳)
- POJ 2187 Beauty Contest【平面最远点对+旋转卡壳】
- POJ-2178 Beauty Contest 凸包+旋转卡壳求最远点对
- 强大的旋转卡壳 POJ 2187 最远点对 POJ 2079点集中面积最大的三角形
- POJ2187(旋转卡壳求平面最远点对)
- [Poj2187]Beauty Contest (旋转卡壳求最远点对)
- 【凸包直径&平面最远点对&对锺点(旋转卡壳)】poj 2187 Beauty Contest
- hdu-2187 Beauty Contest(旋转卡壳求平面最远点对)
- poj 2187 Beauty Contest (旋转卡壳之平面最远点对)
- poj 2187 Beauty Contest 计算几何(凸包+旋转卡壳法)/最远点对
- Extjs4中的Form之fieldset的使用
- C++ 运算符重载
- java排序之一插入排序(一个方法同时给整型和字符串排序)
- Binder框架
- 项目管理--工欲善其事,必先利其器
- poj 2187 旋转卡壳求最远点对的平方
- XML 与 DataSet 互转
- SAP HANA 2. SAP HANA Studio使用insufficient privilege 问题
- Android Dialog 全屏
- 一位女程序员的奋斗路程
- Jquery easyui tree 一些常见操作
- virtualbox安装centos6.4开发环境搭建步骤教程
- 【C++ Primer】顺序容器
- 项目管理--名不正则言不顺,言不顺则事不成