【POJ 2187】Beauty Contest 凸包+旋转卡壳
2016-04-04 16:54
453 查看
xuán zhuǎn qiǎ ké模板题
是这么读吧(≖ ‿ ≖)✧
算法挺简单:找对踵点即可,顺便更新答案。
更新求凸包的模板,之前那个太麻烦了hhh
是这么读吧(≖ ‿ ≖)✧
算法挺简单:找对踵点即可,顺便更新答案。
#include<cstdio> #include<cstring> #include<algorithm> #define read(x) x=getint() #define max(a,b) (a)>(b)?(a):(b) #define N 50003 using namespace std; inline int getint() { int k = 0, fh = 1; char c = getchar(); for(; c < '0' || c > '9'; c = getchar()) if (c == '-') fh = -1; for(; c >= '0' && c <= '9'; c = getchar()) k = k * 10 + c - '0'; return k * fh; } inline int sqr(int x) { return x * x; } struct Point { int x, y; Point(int _x = 0, int _y = 0) : x(_x), y(_y) {} } a , tu ; Point operator - (Point a, Point b) { return Point(a.x - b.x, a.y - b.y); } inline int Cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } int n, top = 0; inline bool cmp(Point X, Point Y) { return X.y == Y.y ? X.x < Y.x : X.y < Y.y; } inline void mktb() { for(int i = 1; i <= n; ++i) { while (top > 1 && Cross(tu[top] - tu[top - 1], a[i] - tu[top]) <= 0) --top; tu[++top] = a[i]; } int k = top; for(int i = n - 1; i > 0; --i) { while (top > k && Cross(tu[top] - tu[top - 1], a[i] - tu[top]) <= 0) --top; tu[++top] = a[i]; } } int main() { read(n); for(int i = 1; i <= n; ++i) read(a[i].x), read(a[i].y); sort(a + 1, a + n + 1, cmp); mktb(); int nxt = 2, ans = 0; for(int i = 1; i < top; ++i) { while (Cross(tu[i + 1] - tu[i], tu[nxt + 1] - tu[i]) > Cross(tu[i + 1] - tu[i], tu[nxt] - tu[i])) { ++nxt; if (nxt == top) nxt = 1; } ans = max(ans, sqr(tu[i].x - tu[nxt].x) + sqr(tu[i].y - tu[nxt].y)); } printf("%d\n", ans); return 0; }
更新求凸包的模板,之前那个太麻烦了hhh
相关文章推荐
- POJ1860Currency Exchange
- 方法的覆写
- c++ int和string的互相转换
- 深入理解HTTP协议、HTTP协议原理分析
- ftp/sftp不使用webportal直接登录到目标系统设置文档-麒麟开源堡垒机技术文档之一
- POJ 2488(DFS)
- Android中Gson解析json数据使用@SerializedName注解与java对象不匹配的字段
- 常用方法
- IOS- SDWebImage的作用
- 【160313 18:00】四则运算 2 的单元测试
- Code Forces 18D Seller Bob(简单DP)
- hdoj 1437 天气情况
- 泛型的下限
- 泛型通配符
- Code Forces 18D Seller Bob(简单DP)
- 用php模拟做服务端侦听端口
- SpringMVC学习记录(二)--controller和view的联系
- Memcached Session Manager(MSM)
- POJ题目分类
- 阅读笔记06