poj 2187 Beauty Contest——旋转卡壳
题目: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——旋转卡壳的更多相关文章
- poj 2187:Beauty Contest(旋转卡壳)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 32708 Accepted: 10156 Description Bes ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- poj 2187 Beauty Contest —— 旋转卡壳
题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
随机推荐
- 为什么是link-visited-hover-active
前言 通常我们在设置链接的一些伪类(link,visited,hover,active)样式时,要让不同的状态显示正确的样式,我们需要按一定的顺序设置这些伪类的样式.这里我就按CSS2规范中推荐的顺序 ...
- C++高级编程1 C++速成
C++高级编程1 C++速成 1.常用的预处理指令 #include [file] #define key value 这个是在C中经常使用的,定义常量数值,用于字符串替换的工作. #ifndef k ...
- Viewpager+Fragmnet懒汉式注意
1.new的时候不会触发setUserVisibleHint(): 2.setUserVisibleHint()在ViewPager中当前缓冲页跳转,可见到不可见或者不可见到可见的时候触发: 3.ge ...
- jQuery动画与特效
参考:jQuery权威指南jQuery初步jQuery选择器jQuery操作domjQuery操作dom事件jQuery插件jQuery操作AjaxjQuery动画与特效jQuery实现导航栏jQue ...
- Nginx配置请求转发location及rewrite规则
一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # 因为所有的地址都以 / 开头,所以这 ...
- Ubuntu下sh *.sh使用==操作符执行报错
----<鸟哥的Linux私房菜--基础篇>学习笔记 ubuntu默认的sh是连接到dash,而我们写shell脚本时使用的时bash.bash和dash在一些方面是不兼容的.因此执行同一 ...
- New Concept English three(17)
27W/m 65 Verrazano, an Italian about whom little is known, sailed into New York Harbour in 1524 and ...
- Git远程操作详解(转)
转自:http://www.ruanyifeng.com/blog/2014/06/git_remote.html Git远程操作详解 Git是目前最流行的版本管理系统,学会Git几乎成了开发者的 ...
- wxWidgets的配置
参考 :http://www.codeproject.com/Articles/11515/Introduction-to-wxWidgets 我是将D:\wxWidgets-3.0.1,中 编译过 ...
- SpringMVC札集(05)——SpringMVC参数回显
自定义View系列教程00–推翻自己和过往,重学自定义View 自定义View系列教程01–常用工具介绍 自定义View系列教程02–onMeasure源码详尽分析 自定义View系列教程03–onL ...