题目:http://poj.org/problem?id=2187

学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738

https://www.jianshu.com/p/74c25c0772d6

注意求凸包时先下后上,保持逆时针;

别忘了给点排序囧。

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int const xn=;
int n,tot,ans;
struct P{
int x,y;
P(int x=,int y=):x(x),y(y) {}
bool operator < (const P &b) const
{return x<b.x||(x==b.x&&y<b.y);}
}p[xn],c[xn];
P operator - (const P &a,const P &b){return P(a.x-b.x,a.y-b.y);}
int cross(P a,P b){return a.x*b.y-a.y*b.x;}
int maxx(int x,int y){return x<y?y:x;}
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
void find()
{
sort(p+,p+n+);//!
for(int i=;i<=n;i++)//under
{
while(tot>&&cross(c[tot]-c[tot-],p[i]-c[tot])<=)tot--;
c[++tot]=p[i];
}
int num=tot;
for(int i=n-;i;i--)//top
{
while(tot>num&&cross(c[tot]-c[tot-],p[i]-c[tot])<=)tot--;
c[++tot]=p[i];
}
tot--;//p[1]
}
int sqr(int x){return x*x;}
int disq(P a,P b){return sqr(a.x-b.x)+sqr(a.y-b.y);}
void work()
{
ans=disq(c[],c[]); c[tot+]=c[];
for(int i=,p=;i<=tot;i++)
{
while(cross(c[p]-c[i],c[p]-c[i+])<cross(c[p+]-c[i],c[p+]-c[i+]))
{p++; if(p==tot+)p=;}
ans=maxx(ans,maxx(disq(c[p],c[i]),disq(c[p+],c[i+])));
}
}
int main()
{
n=rd();
for(int i=;i<=n;i++)p[i].x=rd(),p[i].y=rd();
find(); work();
printf("%d\n",ans);
return ;
}

poj 2187 Beauty Contest —— 旋转卡壳的更多相关文章

  1. poj 2187:Beauty Contest(旋转卡壳)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32708   Accepted: 10156 Description Bes ...

  2. poj 2187 Beauty Contest——旋转卡壳

    题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  3. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  4. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  5. poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)

    链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...

  6. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

  7. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  8. POJ 2187 Beauty Contest(凸包,旋转卡壳)

    题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...

  9. POJ 2187 Beauty Contest(凸包+旋转卡壳)

    Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...

随机推荐

  1. DP(正解完全背包+容斥)

    DP Time Limit:10000MS     Memory Limit:165888KB     64bit IO Format:%lld & %llu Submit Status De ...

  2. SQLite支持的并发访问数

    SQLite objects created in a thread can only be used in that same thread.The object was created in th ...

  3. Django在不启动server的情况下调用方法

    from django.conf import settingsfrom django import template settings.configure() a = template.Templa ...

  4. Tensorflow 初级教程(一)

    初步介绍 Google 于2011年推出人工深度学习系统——DistBelief.通过DistBelief,Google能够扫描数据中心数以千计的核心,并建立更大的神经网络.Google 的这个系统将 ...

  5. 基于Linux Shell的开机启动服务

    CentOS重启后,很多服务需要手动启动,很是麻烦,今天把需要开机启动或关闭的服务整理了一下,放入Linux Shell中,再将该Shell加入/etc/rc.local中,即可实现存储的自动挂载.S ...

  6. JQuery 双击动态编辑

             $(this).append(input);            $("input#temp").focus();            $("inp ...

  7. spring-boot2

    1.Spring Boot 1.1.什么是Spring Boot Java是静态语言,先变异后运行都是静态语言,不编译直接运行是动态语言(js是动态语言不需要编译,因为浏览器可以直接解析).Java笨 ...

  8. dev系列之gridview

    gridview新增一行就激活编辑,及显示闪动的光标 gridView1.ShowEditor(); 隐藏Gridview表头上面的panel this.gridView1.OptionsView.S ...

  9. 【leetcode刷题笔记】Spiral Matrix

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  10. Python 3 接口与归一化设计

    一.接口与归一化设计: 1.归一化让使用者无需关心对象的类是什么,只需要知道这些对象都具备某些功能就可以了,这极大地降低了使用者的使用难度. 2.归一化使得高层的外部使用者可以不加区分的处理所有接口兼 ...