POJ 2187 Beauty Contest 旋转卡壳入门题
来源:互联网 发布:颜色代码源码 编辑:程序博客网 时间:2024/06/01 23:20
入门:http://blog.csdn.net/accry/article/details/6070626
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 50005struct point{ int x, y;}p[maxn], res[maxn<<1];int max(int a, int b){ return a > b ? a : b;}int xmult(point o, point a, point b){ return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);}bool cmp(point a, point b){ return a.y < b.y || a.y == b.y && a.x < b.x;}int dis(point a, point b){ return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);}int graham(int n, point *p){ int top = 1, i; sort(p, p + n, cmp); if(n == 0) return 0; res[0] = p[0]; if(n == 1) return 1; res[1] = p[1]; if(n == 2) return 2; for(i = 3; i < n; i++) { while(top >= 1 && xmult(res[top-1], res[top], p[i]) <= 0) top--; res[++top] = p[i]; } res[++top] = p[n-2]; int t = top; for(i = n-3; i >= 0; i--) { while(top >= t && xmult(res[top-1], res[top], p[i]) <= 0) top--; res[++top] = p[i]; } return top;}int rotating_calipers(int n, point *p){ int i, q = 1, ans = 0; p[n] = p[0]; for(i = 0; i < n; i++) { while( xmult(p[i], p[i+1], p[q+1]) > xmult(p[i], p[i+1], p[q])) q = (q + 1) % n; ans = max(ans, max(dis(p[i], p[q]), dis(p[i+1], p[q+1]) ) ); } return ans;}int main(){ int i, j; int n; while( ~scanf("%d", &n)) { for(i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].y); int cnt = graham(n, p); printf("%d\n", rotating_calipers(cnt, res) ); } return 0;}
- POJ 2187 Beauty Contest 旋转卡壳入门题
- Poj 2187 Beauty Contest(旋转卡壳)
- poj 2187 Beauty Contest(旋转卡壳)
- POJ 2187: Beauty Contest(旋转卡壳)
- POJ 2187 Beauty Contest(旋转卡壳)
- POJ 2187 Beauty Contest 旋转卡壳
- POJ 2187 Beauty Contest 旋转卡壳
- [POJ 2187]Beauty Contest(旋转卡壳)
- POJ 2187 Beauty Contest(旋转卡壳)
- POJ 2187Beauty Contest旋转卡壳
- POJ 2187 Beauty Contest 旋转卡壳
- [POJ 2187]Beauty Contest:旋转卡壳
- 【旋转卡壳】poj 2187 Beauty Contest
- POJ:2187 Beauty Contest 旋转卡壳
- POJ 2187 Beauty Contest(旋转卡壳模板题)
- poj 2187 Beauty Contest(凸包+旋转卡壳)
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
- POJ 2187 Beauty Contest [凸包,旋转卡壳]
- 自动登录的实现
- HDU 2196 Computer 树形DP(2个dfs)
- POJ 4026 Eve 并查集模拟题
- Codeforces Round #142 (Div. 2) 解题报告
- HDU 4126 Genghis Khan the Conqueror prim + 树形DP 好题
- POJ 2187 Beauty Contest 旋转卡壳入门题
- Fedora 下 安装 chrome
- POJ 3436 ACM Computer Factory 拆点 + 最大流
- POJ图论列表,想学图论的可以做下,打*的是经典题,蛮多都比较难,基础知识多看几次再做
- POJ 3469 Dual Core CPU 最小割入门题
- POJ 1815 Friendship 最小割 + 字典序输出割点
- ZOJ 2587 Unique Attack 判最小割唯一
- ZOJ 2314 Reactor Cooling 上下界网络流(无源汇可行流)
- LwIP多TCP连接问题