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 ...
随机推荐
- ADO.NET笔记(一)XML导入导出和数据库
数据导出成XML文件 #region 数据导出成XML文件 string sql = "select Id, CallerNumber, TelNum, StartDateTime, End ...
- UITableView的简单使用
UITableView分为两种style:UITableViewStyleGrouped和UITableViewStylePlain. (一)UITableViewStyleGrouped #impo ...
- sql语句聚合等疑难问题收集
------------------------------------------------------------------------------------ 除法运算 select 500 ...
- 转:ASP.NET中的SESSION实现与操作方法
在ASP.NET中,状态的保持方法大致有:ApplicationState,SessionState,Cookie,配置文件,缓存. ApplicationState 的典型应用如存储全局数据. Se ...
- 关于在windows7中使用Virtual Box 按照 安卓虚拟机几个注意事项
1.选择安卓原生镜像的问题 选择带PC的字眼的,也就是给平板PC使用的那个,我使用的版本是android-x86-4.0-r1-eeepc.iso其他类似版本也是可以的,因为我已经成功实践啦. 下载地 ...
- jquery学习全面总结
本文仅针对jquery的部分知识点做总结,更为全面的可以去官网看中文文档.可以更为详细的了解jquery及其特性. window.onload 和$(document).ready() 我 windo ...
- 关于IE8以上 不引人css 症状
不知道各位有没有体验过 这样的状况 在同一个文件夹中 <!DOCTYPE html> <html> <head> <meta charset="u ...
- 【转】TCP的SEQ和ACK的生成
TCP序列号和确认号详解 完整的PDF下载: 在网络分析中,读懂TCP序列号和确认号在的变化趋势,可以帮助我们学习TCP协议以及排查通讯故障,如通过查看序列号和确认号可以确定数据传输是否乱序.但我在查 ...
- 2014-10 u-boot 顶层config.mk分析
/** ****************************************************************************** * @author Maox ...
- Stimulsoft Reports报表工具
关于第三方的报表工具,网上的种类有很多,一些专门做报表工具的公司,还针对不同平台语言做了分别处理.总之功能都很强大,比较流行和使用广泛的貌似还是国外的产品,版本收费和中文资料匮乏,这都是不可避免的问题 ...