题目链接

题意:就是给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. [BZOJ2152]聪聪可可(点分治)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2152 分析:裸的点分治,对于每课树,记录t[0],t[1],t[2]表示到当前根节点距 ...

  2. 数据库系统原理——ER模型与关系模型

    原文链接: http://blog.csdn.net/haovip123/article/details/21614887 犹记得第一次看<数据库系统原理>时看天书的感觉,云里雾里:现在已 ...

  3. android之Activity回传数据

    约定:当Activity发生跳转时将原来的Activity成为父Activity,将新出现的Activity成为子Activity. 情景设置 下面是个发短信的Activity 当我们点击图中的+按钮 ...

  4. redis入门配置

    简介: Redis是Nosql中比较出名的,分布式数据库缓存,提升相应的速度,降低对数据库的访问! Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,(永久 ...

  5. js实现登陆页面的拖拽功能

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>登 ...

  6. python 批量更改文件名

    工作中遇到一种情况,就是市场部那边经常发过来一些apk的包 但是要求更改名字,文件太多了,没办法,只有想办法了,还好命名都是有规则的 比如说 YZLoan-gdtyyb-V2.23.apk------ ...

  7. Linux_rsyslogd日志服务(二)

    一.rsyslogd日志统一格式 基本日志格式包含以下四列: 1.事件产生的时间 2.发生事件的服务器的主机名 3.产生事件的服务名或程序名 4.事件的具体信息 二./etc/rsyslog.conf ...

  8. splay poj3481

    三种操作 1 k  p  插入一个点 2 输出p最大对应的k 删除这个点 3  输出p最小对应的k 删除这个点 splay  维护一下 一不小心就会超时 #include<stdio.h> ...

  9. html-div中内容自动换行

    <div style='width: 100px;display:block;word-break: break-all;word-wrap: break-word;'> 内容超出div宽 ...

  10. epon e8-c HG220GS超级密码破解

    网上找了很多管理电信e8-c的破解资料,大多都是明文密码,而hg220gs则为加密的密码,找来找去最后终于找到加密方式了base64,真心不容易 下面从其他博文中转载过来留着记录 低端hack.主要是 ...