题目链接

题意:就是给N个点的坐标,然后求任意两个点距离的平方最大的值

枚举超时。

当明白了 最远距离的两个点一定在凸包上,一切就好办了。求出凸包,然后枚举

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const double eps = 1e-;
const int Max = + ;
struct Node
{
int x, y;
};
Node node[Max], ch[Max];
int cmp(Node tempx, Node tempy)
{
if(tempx.y == tempy.y)
return tempx.x < tempy.x;
return tempx.y < tempy.y;
}
int xmult(Node p1, Node p2, Node p3)
{
return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
}
int andrew(int n)
{
int len, top = ;
ch[] = node[];
ch[] = node[];
for(int i = ; i < n; i++)
{
while(top && xmult(ch[top - ], ch[top], node[i]) <= )
top--;
ch[ ++top ] = node[i];
}
len = top;
ch[ ++top ] = node[n - ];
for(int i = n - ; i >= ; i--)
{
while(len != top && xmult(ch[top - ], ch[top], node[i]) <= )
top--;
ch[ ++top ] = node[i];
}
return top;
}
int dist(Node p1, Node p2)
{
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) ;
}
int get_max(int x, int y)
{
if(x - y > )
return x;
return y;
}
int main()
{
int n;
while( scanf("%d", &n) != EOF) {
for(int i = ; i < n; i++)
scanf("%d%d", &node[i].x, &node[i].y);
sort(node, node + n, cmp);
int top = andrew(n); int ans = ;
if(top > )
{
for(int i = ; i < top; i++)
{
for(int j = ; j < top; j++)
{
ans = get_max(ans, dist(ch[i], ch[j]));
}
}
}
else
{
ans = dist(ch[], ch[]);
}
printf("%d\n", ans);
}
return ;
}

POJ2187Beauty Contest(任意点的最远距离 + 凸包)的更多相关文章

  1. poj2187Beauty Contest(凸包直径)

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

  2. POJ2187Beauty Contest

    http://poj.org/problem?id=2187 题意 :有一个农场有N个房子,问最远的房子相距多少距离 . 思路 :凸包,旋转卡壳,通过寻找所有的对锺点,找出最远的点对. #includ ...

  3. POJ2187Beauty Contest 旋转卡壳

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

  4. 2018.10.18 poj2187Beauty Contest(旋转卡壳)

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

  5. POJ 3660 Cow Contest 任意两点之间的关系 Floyd

    题意:牛之间有绝对的强弱,给出一些胜负关系,问有多少头牛可以确定其绝对排名. #include <iostream> #include <cstdio> #include &l ...

  6. hdu 2196(求树上每个节点到树上其他节点的最远距离)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2196 思路:首先任意一次dfs求出树上最长直径的一个端点End,然后以该端点为起点再次dfs求出另一个 ...

  7. AtCoder Grand Contest 008题解

    传送门 \(A\) 分类讨论就行了 然而我竟然有一种讨论不动的感觉 int x,y; inline int min(R int x,R int y){return x<y?x:y;} inlin ...

  8. Book of Evil

    Codeforces Round #196 (Div. 2) D:http://codeforces.com/contest/337/status/D 题意:给你一个树,然后树中有一m个点,求到这m个 ...

  9. Ideas and Tricks

    1.树上拓扑排序计数 结论$\dfrac{n!}{\prod\limits_{i=1}^n size_i}$ 对于节点$i$,其子树随意排序的结果是$size[i]!$ 但$i$需要排在第一位,只有$ ...

随机推荐

  1. Java程序-进程中的"进程"

    进程 我们知道程序在磁盘上的时候是静态的,当他被加载到内存的时候,就变成了一个动态的,称为进程,如下图是程序被加载到内存后,在内存中的分布情况如下      此图来自http://blog.csdn. ...

  2. Simple File System

    This is my operating system class design. scanner.h #include<string> using namespace std; #pra ...

  3. Sublime Text 3 常用插件以及安装方法(vue 插件)

    使用Package Control组件安装 也可以安装package control组件,然后直接在线安装: 按Ctrl+` 调出console 粘贴以下代码到底部命令行并回车: { import u ...

  4. linux基础-第十三单元 硬盘分区、格式化及文件系统的管理二

    第十三单元 硬盘分区.格式化及文件系统的管理二 文件系统的挂载与卸载 什么是挂载 mount命令的功能 mount命令的用法举例 umount命令的功能 umount命令的用法举例 利用/etc/fs ...

  5. C#高级特性_Lambda

    “Lambda 表达式”(lambda expression)是一个匿名函数 省略delegate,甚至省略参数类型: 直接用(参数)=> {语句或表达式} 例如: button1.Click ...

  6. oracle-day1

    今天的学习内容是oracle产品的三种安装方式,还有使用dbca静默建库 oracle产品的三种安装方式分别为: 1.图形化(Java向导)安装引导 2.使用应答文件静默安装 3.直接将装好的orac ...

  7. colpick-jQuery颜色选择器使用说明

      一.demo及下载网址:http://www.htmleaf.com/jQuery/Color-Picker/20141108417.html   二.使用效果   三.使用方法 1.引入js和c ...

  8. js处理日期格式化-年月日周

    方法一 Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, //month ...

  9. C#-WinForm-进程、线程

    进程:一个程序就是一个进程,也有可能一个程序需要多个进程来支持的情况,比如QQ 点击按钮打开记事本,静态方法 public partial class Form3 : Form { public Fo ...

  10. JS 打印功能代码可实现打印预览、打印设置等

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