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 ...
随机推荐
- 记录-spring MultipartFile 文件上传
注意:以下上传和下载方法未必完全正确,不同浏览器效果不同,建议不要使用IE /** * 简单的文件上传 * @author:qiuchen * @createTime:2012-6-19 * @par ...
- android菜鸟学习笔记18----Android数据存储(二)SharedPreferences
数据存储的方式,有比直接文件读写更加简便的方式,那就是操作SharedPreferences. SharedPreferences一般用于存储用户的偏好设定,暂时不支持多进程操作. SharedPre ...
- dubbo启动报错多个资源争缓存问题
Dubbo Failed to save registry store file, cause: Can not lock the registry cache file 目录(?)[+] 启动的Du ...
- 让intellij挂在异常处,特别是出现null pointer的地方
1 在Intellij中设置java exception breakpoint 在调试模式下,run->view breakpoints 在java exception breakpoints- ...
- java上传文件,下载文件
1.上传文件 1 protected int doTask(BaseForm form) throws AppException, FatalException, NoExistsException, ...
- ob 函数讲解
ob的基本原则:如果ob缓存打开,则echo的数据首先放在ob缓存.如果是header信息,直接放在程序缓存.当页面履行到最后,会把ob缓存的数据放到程序缓存,然后依次返回给涉猎器.下面我说说ob的基 ...
- mysql设计表时出错
source下面那个字段没有设置类型,类型为空
- J.U.C重入锁
ReentrantLock重入锁 ReentrantLock是Java并发包中互斥锁,它有公平锁和非公平锁两种实现方式, 重入的意思就是,如果已经获得了锁,如果执行期间还需要获得这个锁的话,会直接获得 ...
- UIImageView 获取图片的 宽 高
该文章纯属这两天开发的经验之谈 并且也是平常没注意 这回发现的一个小方法 并且很实用 在开发中 提高了很大的效率 更加符合高保真的要求 通常 美术 切的一些图片 需要 :1还原的 现在 我们一般支持i ...
- iOS 代码延迟执行
1. [NSTread sleepForTimeInterval:0.8f] 这个方法 实际效果 好比打断点 等你再恢复断点执行 2. [self performSelector:@selector ...