POJ 2178 (凸包 旋转卡壳)
来源:互联网 发布:matlab哈密顿回路算法 编辑:程序博客网 时间:2024/05/16 10:15
题意是求平面最远点对距离的平方。
旋转卡壳的板子题。
#include <cstring>#include <cmath>#include <iostream>#include <algorithm>#include <cstdio>using namespace std;typedef unsigned long long ll;#define maxn 51111#define pi acos (-1)#define rotate Rotateconst double eps = 1e-8;int dcmp (double x) { if (fabs (x) < eps) return 0; else return x < 0 ? -1 : 1;}struct point { double x, y; point (double _x = 0, double _y = 0) : x(_x), y(_y) {} 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); } bool operator < (const point &a) const { return x < a.x || (x == a.x && y < a.y); } bool operator == (const point &a) const { return dcmp (x-a.x) == 0 && dcmp (y-a.y) == 0; }};point operator * (point a, double p) { return point (a.x*p, a.y*p);}double cross (point a, point b) { return a.x*b.y-a.y*b.x;}double dot (point a, point b) { return a.x*b.x + a.y*b.y;}int n, m;point p[maxn], ch[maxn];int ConvexHull () { sort (p, p+n); int m = 0; for (int i = 0; i < n; i++) { while (m > 1 && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } int k = m; for (int i = n-2; i >= 0; i--) { while (m > k && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0) m--; ch[m++] = p[i]; } if (n > 1) m--; return m;}double dis (point a, point b) { double xx = a.x-b.x, yy = a.y-b.y; return xx*xx+yy*yy;}double rotate_calipers (point *p) { double ans = 0; int cur = 1; for (int i = 0; i < m; i++) { while (cross (p[i]-p[(i+1)%m], p[(cur+1)%m]-p[cur]) < 0) cur = (cur+1)%m; ans = max (ans, max (dis (p[i], p[cur]), dis (p[(i+1)%m], p[(cur+1)%m]))); } return ans;}int main () { //freopen ("in", "r", stdin); ios::sync_with_stdio(0); while (scanf ("%d", &n) == 1) { for (int i = 0; i < n; i++) { scanf ("%lf%lf", &p[i].x, &p[i].y); } m = ConvexHull (); printf ("%lld\n", (long long) rotate_calipers (ch)); } return 0;}
0 0
- POJ 2178 (凸包 旋转卡壳)
- POJ 2187 凸包+旋转卡壳
- POJ 2187 凸包&旋转卡壳
- POJ 2079 Triangle 凸包+旋转卡壳
- poj 2079 Triangle 凸包+旋转卡壳
- poj 2187(凸包+旋转卡壳)
- poj 2187 Beauty Contest(凸包+旋转卡壳)
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
- poj 2079 Triangle(凸包+旋转卡壳)
- POJ 2187 Beauty Contest [凸包,旋转卡壳]
- POJ 2187 Beauty Contest 构造凸包 + 旋转卡壳
- poj-2187-凸包-旋转卡壳法求直径
- POJ 2079 Triangle (凸包中的最大三角形&旋转卡壳)
- POJ 2187 求多边形直径(凸包+旋转卡壳)
- Poj 2187 Beauty Contest_旋转凸包卡壳
- POJ 3608 求两凸包的最小距离 (凸包+旋转卡壳)
- POJ 2187 Beauty Contest 构造凸包 + 旋转卡壳
- poj 2187 Beauty Contest 题解(凸包模板+旋转卡壳)
- sql异常
- 为什么我用VS2010做EXTPB.NET程序,有些文件没有发布出去?
- JQuery.Ajax之错误调试帮助信息
- 【知识】Eclipse中搜索的使用
- swiper下loop模式点击事件无效的原因
- POJ 2178 (凸包 旋转卡壳)
- main()函数常用的格式:main(int argc,char **argv)
- java socket编程
- 初识CoreData
- Zigbee网关 Zstack增加串口功能2-修改应用层APP/ZigbeeGateWay.c
- 使用Cocos2d-lua开发植物大战僵尸11-植物类的实现下
- XStream两分钟教程(译)
- 服务器tcp连接timewait过多优化及详细分析
- UniFi - Set minimum RSSI for clients