• 【洛谷 P1452】 Beauty Contest (二维凸包,旋转卡壳)


    题目链接
    旋转卡壳模板题把。
    有时间再补总结吧。

    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    const int MAXN = 100010;
    struct point{
    	int x, y;
    }p[MAXN];
    int operator * (point a, point b){    // a x b
    	return a.x * b.y - b.x * a.y;
    }
    point operator - (point a, point b){
    	return (point){ a.x - b.x, a.y - b.y };
    }
    int cmp1(const point a, const point b){
    	return a.x == b.x ? a.y < b.y : a.x < b.x;
    }
    inline double k(point a, point b){
    	return a.x == b.x ? 1e18 : ((double)b.y - a.y) / (b.x - a.x);
    }
    inline double dis(point a, point b){
    	int px = b.x - a.x, py = b.y - a.y;
    	return sqrt(px * px + py * py);
    }
    inline int dp(point a, point b){
    	int px = b.x - a.x, py = b.y - a.y;
    	return px * px + py * py;
    }
    int n, top, tp, ans;
    point st[MAXN], ts[MAXN];
    inline double mult(point a, point b, point c){
    	return (a - c) * (b - c);
    }
    int SpecialJudge(){
    	for(int i = 2; i <= n; ++i)
    	   if(p[i].y != p[i - 1].y)
    	     return 0;
    	return 1;
    }
    int main(){
    	scanf("%d", &n);
    	for(int i = 1; i <= n; ++i)
    	   scanf("%d%d", &p[i].x, &p[i].y);
    	if(SpecialJudge()){
    	  int Min = 0x3f3f3f3f, Max = -0x3f3f3f3f;
    	  for(int i = 1; i <= n; ++i){
    	  	 Min = min(Min, p[i].x);
    	  	 Max = max(Max, p[i].x);
    	  }
    	  printf("%d
    ", (Max - Min) * (Max - Min));
    	  return 0;
        }
    	sort(p + 1, p + n + 1, cmp1);
    	for(int i = 1; i <= n; ++i){
    	   while(top > 1 && k(st[top - 1], p[i]) < k(st[top - 1], st[top])) --top;
    	   st[++top] = p[i];
        }
    	for(int i = 1; i <= n; ++i){
    	   while(tp > 1 && k(ts[tp - 1], p[i]) > k(ts[tp - 1], ts[tp])) --tp;
    	   ts[++tp] = p[i];
        }
        for(int i = tp - 1; i; --i) st[++top] = ts[i];
        int j = 2;
        for(int i = 1; i <= top; ++i){
           while(mult(st[i], st[i + 1], st[j]) < mult(st[i], st[i + 1], st[j + 1]))
           	 if(++j > top) j = 1;
           ans = max(ans, max(dp(st[i], st[j]), dp(st[i + 1], st[j])));
        }
        printf("%d
    ", ans);
    	return 0;
    }
    
  • 相关阅读:
    自考新教材-p282
    p281
    自考新教材-p279_2
    用jmap分析java程序
    用jstack工具分析java程序
    java应用maven插件动态生成webservice代码
    Java对信号的处理
    【OracleDB】 01 概述和基本操作
    【Oracle】Windows-19C 下载安装
    【Hibernate】06 查询API
  • 原文地址:https://www.cnblogs.com/Qihoo360/p/10316656.html
Copyright © 2020-2023  润新知