POJ2187Beauty Contest
http://poj.org/problem?id=2187
题意 :有一个农场有N个房子,问最远的房子相距多少距离 。
思路 :凸包,旋转卡壳,通过寻找所有的对锺点,找出最远的点对。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm> using namespace std ; typedef long long ll ;
const int maxn = ; struct point
{
int x ;
int y ;
}p[maxn],ch[maxn] ; int det(int x1,int y1,int x2,int y2 )//叉积
{
return x1*y2-x2*y1 ;
}
int side(point a,point b,point p)//两个向量的叉积,平行四边形面积
{
return det(b.x-a.x,b.y-a.y,p.x-a.x,p.y-a.y) ;
}
int squre_dis(point a,point b)//两点之间的距离
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) ;
}
bool cmp(point a,point b)
{
if(a.y == b.y)
return a.x < b.x ;
return a.y < b.y ;
}
int convex_hull(point p[],int n)//凸包
{
sort(p,p+n,cmp) ;
ch[] = p[] ;
if(n == )
{ch[] = ch[] ;return ;}
ch[] = p[] ;
if(n == )
{ch[] = ch[] ;return ;}
int ix = ;
for(int i = ; i < n ; i++)
{
while(ix > &&side(ch[ix-],ch[ix-],p[i] )<= )
--ix ;
ch[ix++] = p[i] ;
}
int t = ix ;
ch[ix++] = p[n-] ;
for(int i = n- ; i >= ; i--)
{
while(ix > t && side(ch[ix-],ch[ix-],p[i]) <= )
--ix ;
ch[ix++] = p[i] ;
}
return ix- ;
}
//int dia_numerator(int cn)
//{
// int dia = 0;
// for(int i = 0 ; i < cn ; i++)
// {
// for(int j = 0 ; i < cn ; j++)
// {
// int t = squre_dis(ch[i],ch[j]) ;
// dia = t > dia ? t : dia ;
// }
// }
// return dia ;
//}
int dia_rotating_calipers(int n)//旋转卡壳
{
int dia = ;
int q = ;
for(int i = ; i < n ; i++)
{
while(side(ch[i],ch[i+],ch[q+]) > side(ch[i],ch[i+],ch[q]))
q = (q+)%n ;
dia = max(dia,max(squre_dis(ch[i],ch[q]),squre_dis(ch[i+],ch[q+]))) ;
}
return dia ;
}
int main()
{
int n,cn ;
scanf("%d",&n) ;
for(int i = ; i < n ; i++)
scanf("%d %d",&p[i].x,&p[i].y) ;
cn = convex_hull(p,n) ;
printf("%d\n",dia_rotating_calipers(cn)) ;
return ;
}
POJ2187Beauty Contest的更多相关文章
- POJ2187Beauty Contest(任意点的最远距离 + 凸包)
题目链接 题意:就是给N个点的坐标,然后求任意两个点距离的平方最大的值 枚举超时. 当明白了 最远距离的两个点一定在凸包上,一切就好办了.求出凸包,然后枚举 #include <iostream ...
- poj2187Beauty Contest(凸包直径)
链接 利用旋转卡壳 参考博客http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <iostream> ...
- POJ2187Beauty Contest 旋转卡壳
题目链接 http://poj.org/problem?id=2187 先求凸包 再求凸多边形直径 旋转卡壳模板题 #include<cstdio> #include<cstring ...
- 2018.10.18 poj2187Beauty Contest(旋转卡壳)
传送门 旋转卡壳板子题. 就是求凸包上最远点对. 直接上双指针维护旋转卡壳就行了. 注意要时刻更新最大值. 代码: #include<iostream> #include<cstdi ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu 4946 2014 Multi-University Training Contest 8
Area of Mushroom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2016 Multi-University Training Contest 2 D. Differencia
Differencia Time Limit: 10000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 2016 Multi-University Training Contest 1 G. Rigid Frameworks
Rigid Frameworks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdu-5988 Coding Contest(费用流)
题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
随机推荐
- boost库区间range基本原理及使用实例
由 www.169it.com 搜集整理 区间的概念类似于STL中的容器概念.一个区间提供了可以访问半开放区间[first,one_past_last)中元素的迭代器,还提供了区间中的元素数量的信息. ...
- Linux系统下给VMWare安装Tools
1.进入Linux系统. 2.在VMware的窗口菜单中选VM >> install VMware Tools,虚拟机自动将VMware-tools装入虚拟光驱中. 3.在虚拟光驱里找出V ...
- (转)印度建全球最大生物识别数据库,MongoDB安全受质疑
受棱镜门影响,各界对Aadhar的质疑从是否将威胁人民隐私与安全,转而聚焦在 Aadhar 搜集.储存以及处理资料的方法,以及美国新创公司 MongoDB 在计划中扮演的角色. 泱泱大国印度一直以来都 ...
- OpenCV和Matplotlib色彩空间模式不一致的问题
当用OpenCV读取彩色图像时,OpenCV是以(BGR)的顺序存储图像数据的,而Matplotlib是以(RGB)的顺序显示图像的. 可以用下面的程序来证明这一点 import cv2 import ...
- Poj 3062 Celebrity jeopardy
1.Link: http://poj.org/problem?id=3062 2.Content: Celebrity jeopardy Time Limit: 1000MS Memory Lim ...
- mysql 运行sql脚本文件
#只运行,不导出 mysql> source /home/user/to_run.sql; #导出 $ mysql -h host -u user -ppassword database < ...
- javascript之数据推送
我们使用ajax与后台服务进行交互,常常是通过触发事件来单次交互,但对于有些web应用来说,需要前台与后台保持长连接,前端不定时地接收后台推送的数据信息, 例如:股票行情分析.聊天室和网页在线游戏等. ...
- 【Winform】无法嵌入互操作类型
在使用Interop.SQLDMO进行数据库还原操作时,在vs2010编译时出现:无法嵌入互操作类型“……”,请改用适用的接口的解决方法 解决方案: 选中项目中引入的dll,鼠标右键,选择属性,把“嵌 ...
- 如何实现phpcms v9_4X版本tag的伪静态?
这两个月来写的文章越来越少了,不是懒,因为太忙了--为客户赶做网站.因为客户指定要使用phpcms v9,还要求使用phpcms v9_42版本实现tag伪静态,在接手的时候phpcms v9_42是 ...
- scala知识点(二)
Scala允许使用三个引号来进行多行字符引用:(引自) val longString = """Line 1 Line Line """; ...