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 个点中最远的两个点距离的平方 思路:最远点对一定会在凸包的顶点上,然后直接暴力找一下凸包顶点中距离最远的两个点 /******************* ...
随机推荐
- linux环境下java读取sh脚本并执行
Process process; String cmd = "/home/ty/t.sh";//这里必须要给文件赋权限 chmod u+x fileName; ...
- ps&&/proc/pid/xxx
ps 如果想看一个进程的启动时间,可以用lstart来看 [root@jiangyi02.sqa.zmf /home/ahao.mah] #ps -eo pid,lstart,etime,cmd |g ...
- 【转】基于Qt, TUIO和TSLIB的嵌入式Linux下的多点触摸设计
这个教程描述了在嵌入式linux下使用Qt如何设置一个支持多点触摸和单点触摸的输入系统.这里假定你已经有了对应的驱动程序,驱动可以从触摸屏的厂商那里获得或者使用一个linux 内核源码中已经存在的驱动 ...
- 创建UIButton
UIButtonCreate.h #import <UIKit/UIKit.h> @interface UIButtonCreate : UIButton /** * 创建UIButton ...
- 多校联赛2 Problem2 Warm up 求桥的数目+缩点后的树的直径 当时被不知道原因的爆栈爆到无语了。。
Warm up Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total S ...
- 【MySql】Linux下更改转移mysql数据库目录
1.关闭MySql: #service mysqld stop 2.转移数据: #cd /var/lib #ls #cp -a mysql /opt/mysql/ 3.修改配置文件,一下三个: ...
- NFinal学习笔记 02—NFinalBuild
在学习NFinal的过程中发现在线.net编译器Web版—— NFinalBuild 什么是NFinalBuild呢?它就是帮助我们简单又快速的更新我们网站的一种编译器,我们不用再只为了更新.net网 ...
- baidu地图让多个标注出现在最佳视野
原文:http://www.cnblogs.com/milkmap/archive/2011/08/23/2150641.html 摘要: “我有一堆标注,不规则的散落在地图的各个地方,我想把它们展示 ...
- iOS archive(归档)的总结
http://www.cnblogs.com/ios8/p/ios-archive.html
- 1230.2——iOS准备(阅读开发者文档时的笔记)
1.程序启动的过程 .在桌面找到相应的应用的图标 点击图标 .main函数 UIApplication类Every app has exactly one instance of UIAp ...