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的更多相关文章

  1. POJ2187Beauty Contest(任意点的最远距离 + 凸包)

    题目链接 题意:就是给N个点的坐标,然后求任意两个点距离的平方最大的值 枚举超时. 当明白了 最远距离的两个点一定在凸包上,一切就好办了.求出凸包,然后枚举 #include <iostream ...

  2. poj2187Beauty Contest(凸包直径)

    链接 利用旋转卡壳 参考博客http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <iostream> ...

  3. POJ2187Beauty Contest 旋转卡壳

    题目链接 http://poj.org/problem?id=2187 先求凸包 再求凸多边形直径 旋转卡壳模板题 #include<cstdio> #include<cstring ...

  4. 2018.10.18 poj2187Beauty Contest(旋转卡壳)

    传送门 旋转卡壳板子题. 就是求凸包上最远点对. 直接上双指针维护旋转卡壳就行了. 注意要时刻更新最大值. 代码: #include<iostream> #include<cstdi ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. 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) ...

  7. 2016 Multi-University Training Contest 2 D. Differencia

    Differencia Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  8. 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) ...

  9. hdu-5988 Coding Contest(费用流)

    题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Ot ...

随机推荐

  1. Cocos2d-x数据持久化-查询数据

    数据查询一般会带有查询条件,这可以使用SQL语句的where子句实现,但是在程序中需要动态绑定参数给where子句.查询数据的具体操作步骤如下所示.(1) 使用sqlite3_open函数打开数据库. ...

  2. java匿名内部类练习

    interface Inter { void method(); } class Test { //补足代码.通过匿名内部类. /* static class Inner implements Int ...

  3. Qt自定义菜单项

    经常会看到一些菜单的部分项是由几个按钮组成的,如酷狗.QQ.360都有类似菜单,对于常规的菜单项,图标 + 文字 实现一个事件,很容易完成,那么怎么自定义菜单项呢? Qt提供了支持,就是利用QWidg ...

  4. boost::xml——基本操作以及中文乱码解决方案

    下面是本人使用boost库的xml部分的基础操作,并且解决对于大家使用boost库读写中文xml内容出现的乱码问题. 1.实现boost库xml基本操作2.解决boost对xml中中文乱码问题3.实现 ...

  5. mysql 运行sql脚本文件

    #只运行,不导出 mysql> source /home/user/to_run.sql; #导出 $ mysql -h host -u user -ppassword database < ...

  6. 在.NET连接MySQL以及封装好的MySQLHelper.cs

    1.首先上MySQL网站下驱动:http://www.mysql.com/products/connector/ 2.安装下载的安装包 3.我们在Visual Studio里创建一个Web Appli ...

  7. JS焦点图,JS 多个页面放多个焦点图

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. [ Database ] [ Sybase ] [ SQLServer ] sybase 與SQL Server的界接方式

    目前我們有個專案Server A安裝了 SQL Server 2012,有個需求需要連線到另外一台Server B上的 Sybase 12.5的view, 先前試過了很多方法都無法連通.主要的原因是因 ...

  9. ES6学习笔记(二)

    1.数组的解构赋值 基本用法 ES6允许按照一定模式,从数组和对象中提取值,对变量进行赋值,这被称为解构(Destructuring). 以前,为变量赋值,只能直接指定值. var a = 1; va ...

  10. ZENCART 打开/关闭日志文件

    优秀的php开源程序很多都只带生成日志文件的功能,这类功能的开发可以帮助到站长在调试网站的时候及时的改正网站存在的错误,但是这类错误日志由来并非网站出现什么严重不可挽救的错误,大部分是一些未定义变量这 ...