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 ...
随机推荐
- ES6 HttpApplication Middleware
const HttpRequest = function() { this.query = '' } function HttpResponse() { this.body = [] this.sta ...
- 【Python】__all__ 暴露接口
很多东西自己实现起来困难或者写的代码很丑,很多时候是因自己对python不是很了解. 以下内容转载自:点这里 Python 可以在模块级别暴露接口: __all__ = ["foo" ...
- 【问题解决记录】无法识别的标志“-sdlMode”,在“p2”中
本文为大便一箩筐的原创内容,转载请注明出处,谢谢:http://www.cnblogs.com/dbylk/ 这是本人第一次使用MarkDown编辑器,试试看效果-w-,下面是正文: 一.报错原因 昨 ...
- vue请求本地json数据
1.下载vue-resource插件 cnpm install vue-resource 1.2全局引入vue-resource: 在main.js import VueResource from ' ...
- 1: 介绍Prism5.0 Introduction to the Prism Library 5.0 for WPF(英汉对照版)
Prism provides guidance designed to help you more easily design and build rich, flexible, and easy- ...
- centos 7 nginx 远程无法访问的原因
1.购买的阿里云需要添加安全组 80端口就可以用了 2.检查防火墙是否关闭 systemctl stop firewalld 这点很重要 我就是查了一天才发现centos7 防火墙开着 难怪几把搞 如 ...
- html5: 幽灵按钮
html: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...
- Mysql数据库的增删改查
在运行程序之前需要在mysql数据库中创建test数据库,如下图所示: 下面是具体是实现程序: package News; import java.sql.Connection; import jav ...
- js 删除数组的指定元素
//为数组对象增加相应的的方法,直接调用数组的removeByValue方法即可删除指定元素 Array.prototype.removeByValue = function (val) { for ...
- windows下类似Linux下的grep命令
今天要查看windws下代理服务器有哪些IP连接过来,但使用 netstat -na 后出现很多连接会话,不方便查看. 想到Linux下的grep非常方便,于是网络上搜寻,还是有类似的命令findst ...