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 ...
随机推荐
- CentOS7安装配置iptables防火墙
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761 CentOS7默认的防火墙不是iptables,而是firewall ...
- R语言基础2
----------------------------------R语言学习与科研应用,科研作图,数据统计挖掘分析,群:719954246-------------------------- 通常, ...
- 深度学习之 seq2seq 进行 英文到法文的翻译
深度学习之 seq2seq 进行 英文到法文的翻译 import os import torch import random source_path = "data/small_vocab_ ...
- hibernate_exercise-many- to-one(1)
多对一关系 1.创建t_user表.t_group表 2.在eclipse中创建对应的实体类 package com.eneity; public class User { private int i ...
- Oracle12c在Win10上的安装配置实践
1.环境 操作系统:Win10专业版(64位) 数据库:Oracle 12c Release 2(Version 12.2.0.1.0,64位) 2.下载Oracle12c oracle官网下载地址: ...
- "共振式”项目管理
"共振式”项目管理--是我第一个提出的吗?:) 脑子里突然想到项目管理的一些事情,然后想到项目其实是有节奏的,项目中的人员其实如果找到了这个节奏,踏准了节奏,一切将是顺风顺水. 刚准备动笔时 ...
- python Josnp(跨域)
python Josnp(跨域) 所谓的跨域就是进行不用域名内的请求,好比如说我在A域名想访问B域名的内容就是一种跨域的行为. 但是在我们浏览器端会有一个同源策略的设置,这个同源策略只对Ajax请求有 ...
- git出现错误原因解释
原因,在pull下拉代码或者push之前,你本地还有代码没有进行commit. 引起下面的错误. 建议commit后先pull再看看有没有冲突在进行push. git.exe push --pro ...
- JSON.stringify()和JSON.parse()分别是什么
JSON.stringify() 从一个对象中解析出字符串 JSON.stringify({"a":"1","b":"2" ...
- js面向对象之公有、私有、静态属性和方法详解
现下,javascript大行其道,对于网站开发人员来说,javascript是必需掌据的一门语言,但随着jquery等框架的流行和使用,许多人对于原生javascript缺乏深入的理解,习惯了函数式 ...