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>
using namespace std;
int const xn=;
int n,tot,ans;
struct P{
int x,y;
P(int x=,int y=):x(x),y(y) {}
bool operator < (const P &b) const
{return x<b.x||(x==b.x&&y<b.y);}
}p[xn],c[xn];
P operator - (const P &a,const P &b){return P(a.x-b.x,a.y-b.y);}
int cross(P a,P b){return a.x*b.y-a.y*b.x;}
int maxx(int x,int y){return x<y?y:x;}
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
void find()
{
sort(p+,p+n+);//!
for(int i=;i<=n;i++)//under
{
while(tot>&&cross(c[tot]-c[tot-],p[i]-c[tot])<=)tot--;
c[++tot]=p[i];
}
int num=tot;
for(int i=n-;i;i--)//top
{
while(tot>num&&cross(c[tot]-c[tot-],p[i]-c[tot])<=)tot--;
c[++tot]=p[i];
}
tot--;//p[1]
}
int sqr(int x){return x*x;}
int disq(P a,P b){return sqr(a.x-b.x)+sqr(a.y-b.y);}
void work()
{
ans=disq(c[],c[]); c[tot+]=c[];
for(int i=,p=;i<=tot;i++)
{
while(cross(c[p]-c[i],c[p]-c[i+])<cross(c[p+]-c[i],c[p+]-c[i+]))
{p++; if(p==tot+)p=;}
ans=maxx(ans,maxx(disq(c[p],c[i]),disq(c[p+],c[i+])));
}
}
int main()
{
n=rd();
for(int i=;i<=n;i++)p[i].x=rd(),p[i].y=rd();
find(); work();
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——旋转卡壳
题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- 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 ...
随机推荐
- TFS中工作项的定制- 字段功能定义
参考,翻译此页面All FIELD XML Elements Reference(http://msdn.microsoft.com/en-us/library/ms194953.aspx) 对于每一 ...
- phpstorm10激活方法
选择 license server ---> http://idea.lanyus.com/ (末尾的斜杠不能漏了!) 2016-7-5更新 上面的注册方法再试时,已被封杀 2017-9-1 ...
- 【python】-- 事件驱动介绍、阻塞IO, 非阻塞IO, 同步IO,异步IO介绍
事件驱动介绍 一.前言 通常,我们写服务器处理模型的程序时,有以下几种模型: (1)每收到一个请求,创建一个新的进程,来处理该请求: (2)每收到一个请求,创建一个新的线程,来处理该请求: (3)每收 ...
- ASP获取上月本月下月的第一天和最后一天
上月第一天:<%=dateadd("m",-1,year(date)&"-"&month(date)&"-1" ...
- ABAP服务器文件操作
转自http://blog.itpub.net/547380/viewspace-876667/ 在程序设计开发过程中,很多要对文件进行操作,这又分为对本地文件操作和服务器文件操作.对本地文件操作使用 ...
- 小程序canvas转base64方法 使用upng库 亲测没问题
普通字符串base64编码转化可以使用原生的atob和btoa方法 图片转码:传统的图片转base64的方法可以采用FileReader的readAsDataURL()或canvas.toDataUR ...
- 详谈 MySQL Online DDL
作为一名DBA,对数据库进行DDL操作非常多,如添加索引,添加字段等等.对于MySQL数据库,DDL支持的并不是很好,一不留心就导致了全表被锁,经常搞得刚入门小伙伴很郁闷又无辜,不是说MySQL支持O ...
- hid_info函数分析
昨天博文<linux下无线鼠标驱动执行流程>中有一行输出信息很让我迷惑,如下所示: [ :1D57: Mouse [HID Wireless Mouse HID Wireless Mous ...
- SpringBoot2.0之整合RabbitMQ
案例: Springboot 对RabbitMQ的支持 公共的pom: <project xmlns="http://maven.apache.org/POM/4.0.0" ...
- HDU 4267 A Simple Problem with Integers(2012年长春网络赛A 多颗线段树+单点查询)
以前似乎做过类似的不过当时完全不会.现在看到就有点思路了,开始还有洋洋得意得觉得自己有不小的进步了,结果思路错了...改了很久后测试数据过了还果断爆空间... 给你一串数字A,然后是两种操作: &qu ...