题目: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>
#define db double
using namespace std;
const int N=5e4+;
int n,sta[N],top,ans;
struct Node{
int x,y;
Node(int a=,int b=):x(a),y(b) {}
bool operator< (const Node &b)const
{return x<b.x||(x==b.x&&y<b.y);}
Node operator- (const Node &b)const
{return Node(x-b.x,y-b.y);}
}t[N],a[N];
int rdn()
{
int ret=;bool fx=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')fx=;ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return fx?ret:-ret;
}
int Mx(int a,int b){return a>b?a:b;}
int cross(Node u,Node v){return u.x*v.y-u.y*v.x;}
int Sqr(int x){return x*x;}
int dist(Node u,Node v){return Sqr(u.x-v.x)+Sqr(u.y-v.y);}
void rtc()
{
a[n+]=a[];
for(int i=,p=;i<=n;i++)
{
while(cross(a[p+]-a[i],a[p+]-a[i+])>cross(a[p]-a[i],a[p]-a[i+]))//>
{p++;if(p>n)p=;}//for if only 2 ver!!!
ans=Mx(ans,Mx(dist(a[p],a[i]),dist(a[p+],a[i+])));
// ans=Mx(ans,Mx(dist(a[p],a[i+1]),dist(a[p-1],a[i])));
}
}
int main()
{
int tot=rdn();
for(int i=;i<=tot;i++)t[i].x=rdn(),t[i].y=rdn();
sort(t+,t+tot+);
for(int i=;i<=tot;i++)
{
while(top>&&cross(t[i]-t[sta[top]],t[i]-t[sta[top-]])>=)top--;
sta[++top]=i;
}
for(int i=tot-,lm=top;i;i--)
{
while(top>lm&&cross(t[i]-t[sta[top]],t[i]-t[sta[top-]])>=)top--;///top>lm
sta[++top]=i;
}
n=top-;
for(int i=;i<=n;i++)a[i]=t[sta[i]];
rtc(); 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 , 旋转卡壳求凸包的直径的平方

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

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

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

  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. cookie、session、sessionStorage、localStorage

    Cookie cookie是存储在浏览器端,并且随浏览器的请求一起发送到服务器端的,它有一定的过期时间,到了过期时间自动会消失. 首次设置cookie时是由服务器端发送到浏览器端 ,之后每次浏览器发送 ...

  2. Mysql之select

    SELECT {*|<字段列表>}   [   FROM <表1>,<表2>,…,<表n>   WHERE <表达式>   GROUP BY ...

  3. Symmetrical Network Acceleration with EBS 12

    Andy Tremayne, my esteemed colleague and fellow blogger, has published a new whitepaper that discuss ...

  4. 【Raspberry pi】cpu、内存等查看及扩展

    使用树莓派时,需要在其系统中部署几个不同功能的程序系统,并涉及到数据库读写.串口读写.web访问等,使系统使用压力较大,在查看树莓派使用情况时也遇到些许问题. free命令 total used fr ...

  5. 【Error】SSL InsecurePlatform error when using Requests package

    使用requests时会出席SSL InsecurePlatform error when using Requests package的错误,一般情况下python2.7.10以下的环境会出现此错误 ...

  6. echarts在vue中使用的感悟

    echarts在vue中使用的感悟 echarts作为图表展示的强大存在,每当使用后台系统,或多或少都会使用到,但是作为菜鸟的我,则是一路采坑,各种头大,比比皆是,为了避免下次再犯同样的错误,特意记录 ...

  7. zoj1654

    题解: 对于每一联通的x,y 检点 然后交叉的连边 然后二分图 代码: #include<cstdio> #include<cstring> #include<cmath ...

  8. tooltip提示框组件

    Tooltip 提示框组件 可独立于其他组件通过$.fn.tooltip.defaults重写默认的defaults.当用户移动鼠标指针在某个元素上时,出现提示信息窗口来显示额外信息.提示内容可以包含 ...

  9. icmp隧道手工操作

    ICMP协议被用于检测网络连通状态的协议,通常情况下,防火墙会默认放过该协议. 渗透测试中经常出现一种情况是,我们通过某一种方式取得了一台主机的权限,得到了一些文件,比如域hash,密码文件之类的东西 ...

  10. JDK1.7之 HashMap 源码分析

    转载请注明出处:http://blog.csdn.net/crazy1235/article/details/75451812 类继承关系 构造函数 Entry put put putForNullK ...