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$需要排在第一位,只有$ ...
随机推荐
- Log4net使用(二)
日志记录到根目录Log文件夹,文件夹中分LogError与LogInfo文件夹 web.config配置: <configSections> <section name=" ...
- Entity Framework 出现 "此 ObjectContext 实例已释放,不可再用于需要连接的操作" 的错误
原因 Entity的导航属性在View中使用,但是该Entity所在的Context已经在Controller中通过 using 释放掉:但是Entity又具有Deferred Query Evalu ...
- MediaWiki隐藏index
Apache 在httpd.conf配置文件中加载mod_rewrite.so模块,将前面的'#'去掉,如果没有则添加这句话: #LoadModule rewrite_module modules/m ...
- Socket,TCP/IP,UDP,HTTP,FTP
1.Socket:套接字,是传输层协议的一种编程API 作用:用于描述IP地址和端口,区分来自不同应用程序的通信,实现数据传输的并发服务 JDK Socket:在java.net包下有两个类Sock ...
- SpringMVC学习--参数绑定
spring参数绑定过程 从客户端请求key/value数据,经过参数绑定,将key/value数据绑定到controller方法的形参上.springmvc中,接收页面提交的数据是通过方法形参来接收 ...
- SVG的使用
一,svg可以在浏览器中直接打开 二,在html使用<img/>标签引用 三,直接在html中使用svg标签 四,作为css背景 SVG支持ie9+ ,chrome 33.0+,firef ...
- “Ceph浅析”系列之一——前言
开源技术专家章宇同学(@一棹凌烟)在C3沙龙分享过Ceph之后,最近来了劲头,一口气写了一系列<Ceph浅析>的博文,共8篇: "Ceph浅析"系列之一--前言 &qu ...
- 【BZOJ 2733】【HNOI 2012】永无乡 Splay启发式合并
启发式合并而已啦,, 调试时发现的错误点:insert后没有splay,把要拆开的树的点插入另一个树时没有把ch[2]和fa设为null,找第k大时没有先减k,,, 都是常犯的错误,比赛时再这么粗心就 ...
- Region Representaion and Description
两类特征 外部特征(external characteristics), 如boundary 内部特征(internal characteristics), 如像素, color, texture. ...
- Edge Model
三种edge Step (阶梯) Ramp (坡) Roof 因为噪声的存在, ramp edge是最常见的. 一阶和二阶算子在ramp edge处的表现 一阶和二阶算子对噪声的敏感性 从上自下, 高 ...