http://poj.org/problem?id=2187

题意:求凸包上最远点距离的平方

思路:开始用旋转卡壳求的最远点,WA,改了好久。。后来又改成枚举凸包上的点。。AC了。。

 #include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int N=;
int n;
struct Point
{
int x,y;
Point(int x = ,int y = ):x(x),y(y) {}
bool friend operator < (const Point &a,const Point &b)
{
return a.x < b.x||(a.x==b.x&&a.y < b.y);
} } p[N],ch[N];
typedef Point Vector;
Vector operator-(Point a,Point b)
{
return Vector(a.x-b.x,a.y-b.y);
}
int Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
int Distance(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int Graham()//判断凸包
{
sort(p,p+n);
int m = ;
for (int i = ; i < n; i++)
{
while(m > &&Cross(ch[m-]-ch[m-],p[i]-ch[m-]) <= )
m--;
ch[m++] = p[i];
}
int k = m;
for (int i = n-; i >= ; i--)
{
while(m > k && Cross(ch[m-]-ch[m-],p[i]-ch[m-]) <= )
m--;
ch[m++] = p[i];
}
if (n > )
m--;
return m;
}
int main()
{
scanf("%d",&n);
for (int i = ; i < n; i++)
scanf("%d %d",&p[i].x,&p[i].y);
int cnt = Graham();
int ans = ;
for (int i = ; i < cnt ; i++)
{
for (int j = ; j < i; j++)
{
int dis = Distance(ch[i],ch[j]);
ans = max(ans,dis);
}
}
printf("%d\n",ans);
return ;
}

旋转卡壳的那段代码,不知道哪错了,先保留着吧。。后期再改。。

 int dia_rotating_calipers(int cnt)//旋转卡壳
{
int dia = ;
int q = ;
for (int i = ; i < cnt; i++)
{
while(Cross(ch[i+]-ch[i],ch[q+]-ch[i]) > Cross(ch[i+]-ch[i],ch[q]-ch[i]))
q = (q+)%n;
dia = max(dia,max(Distance(ch[i],ch[q]),Distance(ch[i+],ch[q+])));
}
return dia;
}

Beauty Contest(凸包求最远点)的更多相关文章

  1. POJ 2187 Beauty Contest (求最远点对,凸包+旋转卡壳)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 24283   Accepted: 7420 D ...

  2. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  3. poj 2187 Beauty Contest 凸包模板+求最远点对

    题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...

  4. Beauty Contest(graham求凸包算法)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25256   Accepted: 7756 Description Bess ...

  5. POJ(2187)用凸包求最远点对

    Beauty Contest http://poj.org/problem?id=2187 题目描述:输入n对整数点,求最距离远的点对,输出他们距离的平方和 算法:拿到这个题,最朴素的想法就是用2层循 ...

  6. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

  7. POJ 2187 Beauty Contest 凸包

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27276   Accepted: 8432 D ...

  8. POJ 2187 Beauty Contest [凸包 旋转卡壳]

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36113   Accepted: 11204 ...

  9. Beauty Contest 凸包+旋转卡壳法

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27507   Accepted: 8493 D ...

随机推荐

  1. codeforces_738D

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Memcached 之PHP实现服务器集群一致性hash算法

    /** * memcached 一致性hash,分布式算法 * Class MemcacheCluster */ class MemcacheCluster { protected $nodes = ...

  3. idea热更新配置

    idea部署热启动如下,经过本人实验 在这里只能选择exploded因为它支持热部署 在这里选择如下 到这里已经完成热部署了,如果有问题欢迎反馈给我,我会及时回复

  4. uva 133(The Dole Queue UVA - 133)

    一道比较难想的模拟题,用了队列等东西,发现还是挺难做的,索性直接看了刘汝佳的代码,发现还是刘汝佳厉害! 代码本身难度并不是很大,主要还是p=(p+n+d-1)%n+1;这一句有些难度,实际上经过自己的 ...

  5. discourse论坛迁移

    在源设备的操作备份数据文件tar -czvf discoursefile716.tar.gz /var/discourse然后把此discoursefile716.tar.gz文件传到需要迁移的设备上 ...

  6. 6.3.4 使用marshal 模块操作二进制文件

    Python 标准库 marshal 也可以进行对象的序列化和反序列化,下面的代码进行了简单演示. import marshal x1 = 30 x2 = 5.0 x3 = [1,2,3] x4 = ...

  7. Django——1 环境搭建

    Django 什么是Django 使用前的准备工作 新建项目 开启服务器 新建APP 简单实战 什么是Django框架 http服务器:用来接受用户请求,并将请求转发给web应用框架进行处理.Web应 ...

  8. JavaScript基本知识----操作符,流程控制,循环,字符串方法,数组方式,补充方法

    操作符 算术运算 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  9. ZooKeeper学习总结(1)——ZooKeeper入门介绍

    1. 概述 Zookeeper是Hadoop的一个子项目,它是分布式系统中的协调系统,可提供的服务主要有:配置服务.名字服务.分布式同步.组服务等. 它有如下的一些特点: 简单 Zookeeper的核 ...

  10. JavaSE 学习笔记之异 常(十)

    异 常: 异常:就是不正常.程序在运行时出现的不正常情况.其实就是程序中出现的问题.这个问题按照面向对象思想进行描述,并封装成了对象.因为问题的产生有产生的原因.有问题的名称.有问题的描述等多个属性信 ...