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 ...
随机推荐
- IOS-github优秀开源项目大全
github优秀开源项目大全-iOS 前言 本文旨在搜集github上优秀的开源项目 本文搜集的项目都是用于iOS开发 本文会持续更新… 完整客户端 ioctocat github的iOS客户端,目前 ...
- python 黑客书籍 ——扫描+暴力破解
https://legacy.gitbook.com/book/germey/net-security/details 网络安全 介绍 构建一个端口扫描器 利用Pexpect模拟SSH连接 利用Pxs ...
- lr设置监控本地和远程windows系统资源
LoadRunner之设置监控本地和远程Windows系统资源 一般在客户端通过LoadRunner对服务器进行压力测试,都需要实时监控服务器端的系统资源,本篇主要简单介绍一下如何设置在LoadR ...
- cacti安装和使用
关闭selinux 1.搭建lamp环境 配置apache [root@cacti-server ~]# yum -y install httpd [root@cacti-server ~]# sys ...
- MyCat入门指南
入门篇 1. 安装 1.1从https://github.com/MyCATApache/Mycat-download下载压缩包 1.2解压缩后复制到相应目录下面,比如/usr/local ...
- 006-对象—— static关键字 静态属性和方法的使用
<?php /*static()静态属性: */ //静态属性: /*class Model{ private $mysqli; static $config;//数据库连接状态 functio ...
- input 取消自动填充
增加属性: name="clear"
- getaddrinfo()详解
IPv4中使用gethostbyname()函数完成主机名到地址解析,但是该API不允许调用者指定所需地址类型的任何信息,返回的结构只包含 了用于存储IPv4地址的空间.为了解决该问题,IPv6中引入 ...
- Kotlin Reference (二) Idioms
most from reference 一些常用操作 创建单例类 object 数据类data classList.Map.Array的简单操作Lazy延迟加载属性空类型?空类型表达式?..?:.?. ...
- Kotlin Reference (一) Basic Syntax
什么是Kotlin Kotlin翻译成中文叫"靠他灵",它是由JetBrains公司发明的一种基于JVM的编程语言,目前Google宣布kotlin为Android开发的官方语言. ...