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 ...
随机推荐
- JAVA中RSS解析器(rome.jar和jdom.jar)范例
1.需要 jdom.jar 和 rome.jar 这两个包.2.创建一个项目,web.xml的内容如下: 代码如下 复制代码 <?xml version="1.0" enco ...
- 第七篇、使用UIView的animateWithDuration方法制作简易动画
import UIKit class LolitaCircleButton: UIButton { private var color: UIColor private var imageURL: S ...
- 日常bug及解决方法记录
工作中经常会遇到一些Bug,时间长了有时候就忘记了,这样不好. 特地在这加一个随笔,把以后出现的有价值一点的bug记录在这里,提醒自己,也可以给刚入门的同学一些参考,避免这些坑. 1:界面已经销毁,代 ...
- Java调用外部程序常用算法和封装类
一个项目不可能只使用一种编程语言来开发,也不可能由一个人开发,所以,Java程序员要学会和使用其他编程语言的程序员合作.那么,让我来发布一个工具类--Java外接程序扩展包,并将相应算法发布.Java ...
- iOS 简单总结:description方法\NSLog函数
1.description方法是NSObject自带的方法,包括类方法和对象方法 + (NSString *)description; // 默认返回 类名 - (NSString *)descrip ...
- linux网络编程九:splice函数,高效的零拷贝
from:http://blog.csdn.net/jasonliuvip/article/details/22600569 linux网络编程九:splice函数,高效的零拷贝 最近在看<Li ...
- ajax返回的json内容进行排序
关键方法:sort()用于对数组的元素进行排序. return a.num-b.num是升序: return b.num-a.num;是降序 writeln在输出后面加\n,在文档里是换行,在html ...
- 学习W3SCHOOL 表单验证
//表单学习笔记 //建立一张表单的验证 <!DOCTYPE html> <html> <head> <meta http-equiv="Conte ...
- 直接下载完整chrome浏览器的方法
目前通过下吗的链接可以获得独立的安装包. http://www.google.com/chrome/eula.html?standalone=1&hl=zh-CN
- GridView分页排序
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewPage.asp ...