POJ2187Beauty Contest

时间:2023-01-18 11:10:10

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&lpar;任意点的最远距离 &plus; 凸包&rpar;

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

  2. poj2187Beauty Contest&lpar;凸包直径)

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

  3. POJ2187Beauty Contest 旋转卡壳

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

  4. 2018&period;10&period;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&period; 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&period; Rigid Frameworks

    Rigid Frameworks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  9. hdu-5988 Coding Contest&lpar;费用流&rpar;

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

随机推荐

  1. java调用url接口

    很多简单的接口就是直接一个URl的形式, 怎么调用? HttpClient httpclient=null; PostMethod post=null; try{ httpclient = new H ...

  2. 方法----MessageDigest和DigestUtils加密算法

    总结:使用DigestUtils的方法加密的结果与messageDigest的方法加密结果一致,可使用DigestUtils替换MessageDigest 可省掉部分代码 package com.ac ...

  3. 十个JAVA程序员容易犯的错误

    十个JAVA程序员容易犯的错误 1. Array 转 ArrayList 一般开发者喜欢用: List<String> list = Arrays.asList(arr); Arrays. ...

  4. Aho - Corasick string matching algorithm

    Aho - Corasick string matching algorithm 俗称:多模式匹配算法,它是对 Knuth - Morris - pratt algorithm (单模式匹配算法) 形 ...

  5. SimpleDateFormat用法大全及易错分析

    SimpleDateFormat 使用java语言处理日期相关操作,就不可避免的会使用到SimpleDateFormat.当然了,目前我们采用较多的是Calendar类,通过对之求相关的属性值即可得到 ...

  6. 移植 iperf 网络性能测试工具到 Android-P

    . . . . . 新开发板使用了 Android-P 的方案,WiFi 刚刚调通,为了测试 WiFi 稳定性,需要使用 iperf 工具.但 Android 并没有提供这个工具,只能自己移植一份了. ...

  7. Error&colon; could not open &grave;C&colon;&bsol;Java&bsol;jre7&bsol;lib&bsol;amd64&bsol;jvm&period;cfg&&num;39&semi;

    在运行cmd黑窗口时候出现:Error: could not open `C:\Java\jre7\lib\amd64\jvm.cfg'这样的错误的时候,本人没有删除任何文件,只是重新配置了一下jdk ...

  8. CF &num;442 div2

    A 判断下5个名字出现了几次.pre数据巨弱,就这么一水题在std测刷掉了非常多的人.. /** @Date : 2017-10-24 16:04:41 * @FileName: A.cpp * @P ...

  9. Flex&plus;blazeds实现与mySQL数据库的连接&lpar;已成功实现此文的例子&rpar;

    http://bdk82924.iteye.com/blog/1067285 几个下载地址 blazeds_turnkey_3-0-0-544.zip 下载地址:http://download.mac ...

  10. SQL Server中order by的使用,我们来填坑

    看似很简单是不是? 单列排序,没有任何问题 select * from tableA where age>1 order by age /*后面可以跟上ASC.DESC,默认是ASC升序排列*/ ...