题目: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. 1-10 RHLE7 系统进程管理

    1.1-Linux进程管理 程序.进程.线程 程序:一组指令的集合    QQ 进程:程序的执行就是进程.也可以把进程看成一个独立的程序,在内存中有其对应的代码空间和数据空间,一个进程所拥有的数据和代 ...

  2. vue结合element-ui 的select 全选问题

    下拉列表多选 问题 通过操作 所有来进行全选 全不选问题 element-ui 中 select 记录下自己最近使用element-ui 中的 select多选问题 在element中默认是指单纯多选 ...

  3. linux中的/usr,/var,/opt目录详解

    转自:http://it.greenblogs.org/archives/2008/20113.shtml/ /usr文件系统  /usr 文件系统经常很大,因为所有程序安装在这里. /usr 里的所 ...

  4. socket的几个配置函数

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  5. TCP三次握手,四次挥手,状态变迁图

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  6. JBPM4入门——2.在eclipse中安装绘制jbpm流程图的插件

    本博文只是简要对JBPM4进行介绍,如需更详细内容请自行google 链接: JBPM入门系列文章: JBPM4入门——1.jbpm简要介绍 JBPM4入门——2.在eclipse中安装绘制jbpm流 ...

  7. 正则表达式 preg_match 匹配中文

    preg_match 匹配中文出错 2010年01月06日 星期三 14:55 错误提示: Warning: preg_match() [function.preg-match]: Compilati ...

  8. 【LeetCode 104_二叉树_遍历】Maximum Depth of Binary Tree

    解法一:递归 int maxDepth(TreeNode* root) { if (root == NULL) ; int max_left_Depth = maxDepth(root->lef ...

  9. ajaxFileUpload的data数据带pre标签

    解决办法: var ret = jQuery.parseJSON(jQuery(data).text());

  10. React-Native基础_5.列表视图ListView 网络数据展示

    //获取网络数据 并用列表展示 豆瓣Top250 api /** * Sample React Native App * https://github.com/facebook/react-nativ ...