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$需要排在第一位,只有$ ...
随机推荐
- 深入理解OOP(第一天):多态和继承(初期绑定和编译时多态)
在本系列中,我们以CodeProject上比较火的OOP系列博客为主,进行OOP深入浅出展现. 无论作为软件设计的高手.或者菜鸟,对于架构设计而言,均需要多次重构.取舍,以有利于整个软件项目的健康构建 ...
- Java语法笔记
目录 知识点 不支持 恶心事 与C#的区别 组件 学习资料 母版页 知识点 类 静态方法,即可以在类上被调用,也可以在实例对象上被调用. Java类 先执行静态构造函数,再执行静态方法或静态字段,所以 ...
- PC互联网和移动互联网的本质差别
网一代,我们先称为PC互联网,这大约可以从2010年作为分界,然后就是基于手机,及可穿戴的移动互联网. 在PC时代,软件都很庞大复杂,甚至客端端和网页混合,比如常见的桌面软件,Office及Photo ...
- 【Spring】构建Springboot项目 实现restful风格接口
项目代码如下: package hello; import org.springframework.boot.SpringApplication; import org.springframework ...
- 【Alpha版本】冲刺阶段——Day 3
我说的都队 031402304 陈燊 031402342 许玲玲 031402337 胡心颖 03140241 王婷婷 031402203 陈齐民 031402209 黄伟炜 031402233 郑扬 ...
- php COOKIE和SESSION的一些理解
web服务器是基于http协议的,而http协议是无状态的,导致任意两个请求之间没有联系.但是我们登录网站后,它却能记住我们的身份,这个过程中一定使用了某个标识来区别我们的身份.对于简单数据传输的我们 ...
- 用CSS和jQuery制作简单的下拉框
请选择 百度 谷歌 雅虎 新浪 dowebok 代码 素材 模板 教程 示例下载 // li', function() { var parent = $(this).closest('.select' ...
- 【深入Java虚拟机】之一:Java内存模型与内存溢出
[深入Java虚拟机]之:Java内存区域与内存溢出 高速缓存模型如下: ----------------------------------------------------分割线-------- ...
- C#中的集合有几种?
C#中的集合有几种? Array ArrayList List<T> Stack<T> Queue<T> Dictionary<K,V> HashTab ...
- UITableView的常用属性和代理方法
以下是近期总结的关于tableView的一些属性和代理方法,以及一些常见的问题,现汇总如下,今后还会持续更新,请继续关注: tableView 的头部和尾部视图属性: UISwitch *foot ...