POJ2187Beauty Contest 旋转卡壳
题目链接
http://poj.org/problem?id=2187
先求凸包
再求凸多边形直径
旋转卡壳模板题
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#define N 50010
using namespace std;
int n,tp,ans;
struct P{
int x,y;
bool operator < (const P &b)const{return x==b.x?y<b.y:x<b.x;}
P operator - (const P &b)const{return (P){x-b.x,y-b.y};}
}a[N],s[N];
int dis(P a){return a.x*a.x+a.y*a.y;}
int crs(P a,P b){return a.x*b.y-a.y*b.x;}
void getbag(){
sort(a+,a++n);
for(int i=;i<=n;i++){
while(tp>&&crs(a[i]-s[tp-],s[tp]-s[tp-])>=)--tp;
s[++tp]=a[i];
}
int now=tp;
for(int i=n-;i>=;i--){
while(tp>now&&crs(a[i]-s[tp-],s[tp]-s[tp-])>=)--tp;
s[++tp]=a[i];
}
if(n>)--tp;
}
void rotate(){
int p=;s[tp+]=s[];
for(int i=;i<=tp;i++){
while(crs(s[i+]-s[i],s[p]-s[i])<crs(s[i+]-s[i],s[p+]-s[i]))p=p%tp+;
ans=max(ans,max(dis(s[p]-s[i]),dis(s[p+]-s[i+])));
}
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d",&a[i].x,&a[i].y);
getbag();rotate();
//for(int i=1;i<=tp;i++)printf("%d %d\n",s[i].x,s[i].y);
printf("%d\n",ans);
return ;
}
POJ2187Beauty Contest 旋转卡壳的更多相关文章
- poj2187 Beauty Contest(旋转卡壳)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Beauty Contest Time Limit: 3000MS Memor ...
- 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 ...
- P1452 Beauty Contest 旋转卡壳
\(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...
- poj 2187 Beauty Contest —— 旋转卡壳
题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- 2018.10.18 poj2187Beauty Contest(旋转卡壳)
传送门 旋转卡壳板子题. 就是求凸包上最远点对. 直接上双指针维护旋转卡壳就行了. 注意要时刻更新最大值. 代码: #include<iostream> #include<cstdi ...
- 【POJ】2187 Beauty Contest(旋转卡壳)
http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
随机推荐
- Linux 复习
shift + control + + 终端窗口放大 control + - 终端窗口缩小 ls -alh > laowang.txt 重定向,并覆盖源文件内容 ls -alh >& ...
- oc中protocol、category和继承的区别
OC中protocol.category和继承的区别以前还是有点迷糊,面试的时候说的有点混乱,现在结合一些资料总结一下. 利用继承,多态是一个很好的保持"对扩展开放.对更改封闭"( ...
- Spring MVC Restful Put方法无法获取参数值
Spring MVC Restful 无法通过@ReqeustParam获取参数值 原因是Tomcat只支持POST/GET获取参数值,对于PUT这些方法需要通过HttpPutFormContentF ...
- animation & @keyframes 实现loading效果
效果图截图如下: 直接上代码: html <!DOCTYPE html> <html> <head> <meta charset="utf-8&qu ...
- 利用Node的chokidar 监听文件改变的文件。
最近维护一个项目.每次改完东西,都要上传到服务器.然后有时候就忘记一些东西,于是就想有没有可以方法能监听文件的改变.然后我再利用程序把更改的文件一键上传到服务器. 于是就找到了nodejs 的chok ...
- 为什么 asnyc await 可以提高web程序的吞吐量
(转网上一段话) Web程序天生就是多线程的,且web线程都是跑的线程池线程(使用线程池线程是为了避免不断创建.销毁线程所造成的资源成本浪费),而线程池线程可使用线程数量是一定的,尽管可以设置,但它还 ...
- Angular组件——父组件调用子组件方法
viewChild装饰器. 父组件的模版和控制器里调用子组件的API. 1.创建一个子组件child1里面只有一个greeting方法供父组件调用. import { Component, OnIni ...
- python常用运算符
1. / 浮点除法,就算分子分母都是int类型,也返回float类型,比如我们用4/2,返回2.0 2. // 整数除法,根据分子分母的不同组合,返回的值有差异. 正数//正数,取整,比如5//3,返 ...
- linux下查看mysql日志文件的方法
查看mysql日志方法: mysql默认不允许我们查看日志.需要更改一些设置 1 vi 更改配置文件 允许用户查看日志文件 sudo vi /etc/mysql/mysql.conf.d/mysqld ...
- C#使用Gecko实现浏览器
Gecko就是火狐浏览器的内核啦,速度很快,兼容性比.net内置的webbrowser高到不知哪里去了. 使用Gecko首先要下载一堆依赖库,主要是Skybound.Gecko和xulrunner. ...