zoukankan      html  css  js  c++  java
  • 【POJ 2187】Beauty Contest 凸包+旋转卡壳

    xuán zhuǎn qiǎ ké模板题

    是这么读吧(≖ ‿ ≖)✧

    算法挺简单:找对踵点即可,顺便更新答案。

    #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[N], tu[N];
    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
    ", ans);
    	return 0;
    }
    

    更新求凸包的模板,之前那个太麻烦了hhh

  • 相关阅读:
    DMA
    [计网笔记] 应用层
    为博客添加网易云音乐播放器外链
    acm对拍程序 以及sublime text3的文件自动更新插件auto refresh
    操作系统---内存管理(上) 概念 覆盖交换技术 连续分配管理方式
    操作系统---死锁的检测和解除
    C++ bitset的使用
    Codeforces Round #647 (Div. 2)
    sublime Text3 实现2:1:1三分屏效果
    操作系统---信号量以及四个进程同步问题
  • 原文地址:https://www.cnblogs.com/abclzr/p/5352329.html
Copyright © 2011-2022 走看看