POJ2187Beauty Contest(任意点的最远距离 + 凸包)
题意:就是给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(任意点的最远距离 + 凸包)的更多相关文章
- poj2187Beauty Contest(凸包直径)
链接 利用旋转卡壳 参考博客http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <iostream> ...
- POJ2187Beauty Contest
http://poj.org/problem?id=2187 题意 :有一个农场有N个房子,问最远的房子相距多少距离 . 思路 :凸包,旋转卡壳,通过寻找所有的对锺点,找出最远的点对. #includ ...
- POJ2187Beauty Contest 旋转卡壳
题目链接 http://poj.org/problem?id=2187 先求凸包 再求凸多边形直径 旋转卡壳模板题 #include<cstdio> #include<cstring ...
- 2018.10.18 poj2187Beauty Contest(旋转卡壳)
传送门 旋转卡壳板子题. 就是求凸包上最远点对. 直接上双指针维护旋转卡壳就行了. 注意要时刻更新最大值. 代码: #include<iostream> #include<cstdi ...
- POJ 3660 Cow Contest 任意两点之间的关系 Floyd
题意:牛之间有绝对的强弱,给出一些胜负关系,问有多少头牛可以确定其绝对排名. #include <iostream> #include <cstdio> #include &l ...
- hdu 2196(求树上每个节点到树上其他节点的最远距离)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2196 思路:首先任意一次dfs求出树上最长直径的一个端点End,然后以该端点为起点再次dfs求出另一个 ...
- AtCoder Grand Contest 008题解
传送门 \(A\) 分类讨论就行了 然而我竟然有一种讨论不动的感觉 int x,y; inline int min(R int x,R int y){return x<y?x:y;} inlin ...
- Book of Evil
Codeforces Round #196 (Div. 2) D:http://codeforces.com/contest/337/status/D 题意:给你一个树,然后树中有一m个点,求到这m个 ...
- Ideas and Tricks
1.树上拓扑排序计数 结论$\dfrac{n!}{\prod\limits_{i=1}^n size_i}$ 对于节点$i$,其子树随意排序的结果是$size[i]!$ 但$i$需要排在第一位,只有$ ...
随机推荐
- 各地IT薪资待遇讨论
作为一个搞.net开发的程序员,在北京混了三年半,最近准备辞职到上海找工作.由于对上海的IT行业还不是很了解,在这里想让上海的同行们说下你们的情况,以方便我对自己在上海的定位,当然,其余城市的的同行们 ...
- 【活动】写#听云#原创博文 赢取iPhone 6超级大奖
移动应用的使用量和重要性与日俱增,用户体验的要求也越来越高.与桌面程序相比,移动应用耗电小,速度慢,但手机用户却希望享受到与桌面程序同样的加载速度.那么如何发现移动应用的性能黑洞,优化移动应用性能,这 ...
- matlab如何建立一个空矩阵,然后往里面赋值
x=:; y=[]; :length(x) % y=[y;x(i)];%把每一个x都放到Y里,成为一列 y=[y,x(i)];%把每一个x都放到Y里,成为一行 end
- 东大OJ-1430-PrimeNumbers
题目描述 I'll give you a number , please tell me how many different prime factors in this number. 输入 The ...
- Go--避免SQL注入
避免SQL注入 什么是SQL注入 SQL注入攻击(SQL Injection),简称注入攻击,是Web开发中最常见的一种安全漏洞.可以用它来从数据库获取敏感信息,或者利用数据库的特性执行添加用户,导出 ...
- java保留两位小数
java保留两位小数问题: 方式一: 四舍五入 double f = 111231.5585; BigDecimal b = new BigDecimal(f); d ...
- linux基础-第十三单元 硬盘分区、格式化及文件系统的管理二
第十三单元 硬盘分区.格式化及文件系统的管理二 文件系统的挂载与卸载 什么是挂载 mount命令的功能 mount命令的用法举例 umount命令的功能 umount命令的用法举例 利用/etc/fs ...
- 枚举型Enum和结构型Stuct
枚举型实质就是使用符号来表示的一组相互关联的数据. Season currentSeason,nextSeason; currentSeason = Season.Spring; nextSeason ...
- Java网络编程——概述
一.网络模型 OSI七层模型 应用层 表示层 会话层 传输层: 网络层: 链路层 物理层:比特流 TCP/IP四层模型 应用层 传输层:数据包,TCP/UDP 网络层:数据帧 物理层:比特流 二.网络 ...
- Eclipse导入 appcompat,design兼容包
从Android studio推出1.0正式版后,就一直在as上开发项目,但是最近要测试一个项目,是eclipse结构,导入as后,是各种报错信息,决定改成eclipse. 其中项目中用到了ppcom ...