Poj 2187 Beauty Contest_旋转凸包卡壳
题意:给你n个坐标,求最远的两点距离
思路:用凸包算法求处,各个定点,再用旋转凸包卡壳
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 50010
struct node{
int x,y,d;
}p[N];
int dist(node a,node b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int crossproduct(node a,node b,node c){
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
bool cmp1(node a,node b){
return (a.x==b.x)?(a.y<b.y):(a.x<b.x);
}
bool cmp2(node a,node b){
int cp=crossproduct(p[0],a,b);
if(!cp)
return a.d<b.d;
return cp>0;
}
int Graham(int n){
int i;
sort(p,p+n,cmp1);
for(i=1;i<n;i++)
p[i].d=dist(p[0],p[i]);
sort(p+1,p+n,cmp2);
int top=1;
for(int i=2;i<n;i++){
while(top>0&&crossproduct(p[i],p[top-1],p[top])<=0)
--top;
p[++top]=p[i];
}
p[++top]=p[0];
int R=1,D=0;
for(int L=0;L<top;++L){
while(crossproduct(p[L],p[L+1],p[R])<crossproduct(p[L],p[L+1],p[R+1]))
R=(R+1)%top;
D=max(D,max(dist(p[L],p[R]),dist(p[L+1],p[R+1])));
}
return D;
}
int main(int argc, char** argv) {
int n;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
printf("%d\n",Graham(n));
}
return 0;
}
Poj 2187 Beauty Contest_旋转凸包卡壳的更多相关文章
- 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(凸包,旋转卡壳)
题面 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 ...
- 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(旋转卡壳)
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【凸包周长】
题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 2187 Beauty Contest( 凸包求最远点对 )
链接:传送门 题意:给出 n 个点,求出这 n 个点中最远的两个点距离的平方 思路:最远点对一定会在凸包的顶点上,然后直接暴力找一下凸包顶点中距离最远的两个点 /******************* ...
随机推荐
- Hdu4005-The war(双连通缩点)
In the war, the intelligence about the enemy is very important. Now, our troop has mastered the situ ...
- python中自定义类对象json字符串化的方法
1. 用 json 或者simplejson 就可以 2.定义转换函数: def convert_to_builtin_type(obj): print 'default(', repr(obj), ...
- Hive 8、Hive2 beeline 和 Hive jdbc
1.Hive2 beeline Beeline 要与HiveServer2配合使用,支持嵌入模式和远程模式 启动beeline 打开两个Shell窗口,一个启动Hive2 一个beeline连接hi ...
- discuz!NT 常用操作
一.编辑模版,需在后台模版管理里编辑并提交,这样系统能批量更改相关模版.如:更改登录. 二.config.a 表明:config表示配置文件,a表示配置节名称为a,需在路径 upload_files\ ...
- 使用STS 创建spring配置文件
1.创建一个bean文件 2.输入文件名applicationContext.xml 3.这里会自动显示模板文件 4.创建后,自动填充头不定义 到这里就可以发现,我们创建spring文件时,需要的配置 ...
- poj 1088 滑雪问题
滑雪问题 import java.util.Scanner; public class Main{ static int a[][],r,c; public static void main(Stri ...
- htm跨域锚点定位
a.html <div class="title" id="aaaa">保险服务</div> b.html <div class= ...
- 【转载】"library not found for - "解决办法
[摘要:正在我们编译的时间偶然候会报那个毛病"library not found for - " 因为是我们正在项目中应用了一些第三圆的库,便比方我再应用百度的静态库文件的时间,报 ...
- POJ1275/ZOJ1420/HDU1529 Cashier Employment (差分约束)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 题意:一商店二十四小时营业,但每个时间段需求的出纳员不同,现有n个人申请这份工作, ...
- 安卓初步:通讯技术介绍&&安卓介绍
通讯技术: 1G 模拟制式 只能进行语音通话. 2G GSM, CDMA 收发短信和邮件. 2.5G GPRS, EDGE 访问wap网络数据.(图片, 壁纸, 文 ...