zoukankan      html  css  js  c++  java
  • poj2187 Beauty Contest 旋转卡壳

    链接:http://poj.org/problem?id=2187

    题意:找到一个多边形的直径。

    裸的旋转卡壳……连坑点都没有……不说什么,板子献上……

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cmath>
     6 using namespace std;
     7 const int maxn=50005,inf =0x3f3f3f3f;
     8 struct point
     9 {
    10     int x,y;
    11 }p[maxn];
    12 int n,s[maxn];
    13 int multi(point a,point b,point c)
    14 {
    15     return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
    16 }
    17 int dis(point a,point b)
    18 {
    19     return (b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y);
    20 }
    21 int cmp(point a,point b)
    22 {
    23     int tmp=multi(p[1],a,b);
    24     if(!tmp)return dis(p[1],a)<dis(p[1],b);
    25     return tmp>0;
    26 }
    27 int haha()
    28 {
    29     int j;
    30     int res=0;point begin;int top=-1;
    31     scanf("%d",&n);begin.x=begin.y=10005;
    32     for(int i=1;i<=n;i++)
    33     {
    34         scanf("%d %d",&p[i].x,&p[i].y);
    35         if(p[i].y<begin.y)begin=p[i],j=i;
    36         else if(p[i].y==begin.y&&p[i].x<begin.x)begin=p[i],j=i;
    37     }
    38     if(n==2)
    39     {
    40         printf("%d
    ",dis(p[1],p[2]));
    41         return 0;
    42     }
    43     p[j]=p[1],p[1]=begin;
    44     sort(p+2,p+n+1,cmp);
    45     s[++top]=1,s[++top]=2;
    46     for(int i=3;i<=n;i++)
    47     {
    48         while(top>0&&multi(p[s[top-1]],p[s[top]],p[i])<=0)top--;
    49         s[++top]=i;
    50     }
    51     j=1,s[++top]=1;
    52     for(int i=0;i<top;i++)
    53     {
    54         while(multi(p[s[i]],p[s[i+1]],p[s[j+1]])>multi(p[s[i]],p[s[i+1]],p[s[j]]))j=(j+1)%top;
    55         res=max(res,dis(p[s[i]],p[s[j]]));
    56     }
    57     printf("%d
    ",res);
    58     return 0;
    59 }
    60 int sb=haha();
    61 int main(){;}
    poj2187
  • 相关阅读:
    linux系统安装Mysql
    makefile通用模板
    makefile常用函数
    mysqlconnector安装
    linux添加默认路由route
    .h文件与.hpp文件的区别
    ubuntu20优化开机启动
    [javascript]js原型链以及原型链继承
    webpack4.*入门笔记
    图像编程:图片大小关系
  • 原文地址:https://www.cnblogs.com/Loser-of-Life/p/7296032.html
Copyright © 2011-2022 走看看