Beauty Contest(凸包求最远点)
http://poj.org/problem?id=2187
题意:求凸包上最远点距离的平方
思路:开始用旋转卡壳求的最远点,WA,改了好久。。后来又改成枚举凸包上的点。。AC了。。
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int N=;
int n;
struct Point
{
int x,y;
Point(int x = ,int y = ):x(x),y(y) {}
bool friend operator < (const Point &a,const Point &b)
{
return a.x < b.x||(a.x==b.x&&a.y < b.y);
} } p[N],ch[N];
typedef Point Vector;
Vector operator-(Point a,Point b)
{
return Vector(a.x-b.x,a.y-b.y);
}
int Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
int Distance(Point a,Point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int Graham()//判断凸包
{
sort(p,p+n);
int m = ;
for (int i = ; i < n; i++)
{
while(m > &&Cross(ch[m-]-ch[m-],p[i]-ch[m-]) <= )
m--;
ch[m++] = p[i];
}
int k = m;
for (int i = n-; i >= ; i--)
{
while(m > k && Cross(ch[m-]-ch[m-],p[i]-ch[m-]) <= )
m--;
ch[m++] = p[i];
}
if (n > )
m--;
return m;
}
int main()
{
scanf("%d",&n);
for (int i = ; i < n; i++)
scanf("%d %d",&p[i].x,&p[i].y);
int cnt = Graham();
int ans = ;
for (int i = ; i < cnt ; i++)
{
for (int j = ; j < i; j++)
{
int dis = Distance(ch[i],ch[j]);
ans = max(ans,dis);
}
}
printf("%d\n",ans);
return ;
}
旋转卡壳的那段代码,不知道哪错了,先保留着吧。。后期再改。。
int dia_rotating_calipers(int cnt)//旋转卡壳
{
int dia = ;
int q = ;
for (int i = ; i < cnt; i++)
{
while(Cross(ch[i+]-ch[i],ch[q+]-ch[i]) > Cross(ch[i+]-ch[i],ch[q]-ch[i]))
q = (q+)%n;
dia = max(dia,max(Distance(ch[i],ch[q]),Distance(ch[i+],ch[q+])));
}
return dia;
}
Beauty Contest(凸包求最远点)的更多相关文章
- POJ 2187 Beauty Contest (求最远点对,凸包+旋转卡壳)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 24283 Accepted: 7420 D ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- poj 2187 Beauty Contest 凸包模板+求最远点对
题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...
- Beauty Contest(graham求凸包算法)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25256 Accepted: 7756 Description Bess ...
- POJ(2187)用凸包求最远点对
Beauty Contest http://poj.org/problem?id=2187 题目描述:输入n对整数点,求最距离远的点对,输出他们距离的平方和 算法:拿到这个题,最朴素的想法就是用2层循 ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ 2187 Beauty Contest 凸包
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27276 Accepted: 8432 D ...
- POJ 2187 Beauty Contest [凸包 旋转卡壳]
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36113 Accepted: 11204 ...
- Beauty Contest 凸包+旋转卡壳法
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27507 Accepted: 8493 D ...
随机推荐
- 在oninitdialog后添加初始化变量
需要 UpdateData(FALSE); 刷新界面 不然有时会不显示.
- Android 双屏异显
android双屏是克隆模式,如果要在第二屏幕显示不同内容,需要自定义一个Presentation类 1.先设置权限 (刚开始折腾很久没有效果,后来发现是没设置权限) <!-- 显示系统窗口权限 ...
- sysbench_cpu
5 core : 25.2848s [root@jiangyi01.sqa.zmf /home/ahao.mah/ALIOS_QA/tools/sysbench] #sysbench --num-th ...
- Dinic当前弧优化 模板及教程
在阅读本文前,建议先自学最大流的Ek算法. 引入 Ek的核心是执行bfs,一旦找到增广路就停下来进行增广.换言之,执行一遍BFS执行一遍DFS,这使得效率大大降低.于是我们可以考虑优化. 核心思路 在 ...
- 《零压力学Python》 之 第一章知识点归纳
第一章(初识Python)知识点归纳 Python是从ABC语言衍生而来的 ABC语言是Guido参与设计的一种教学语言,为非专业编程人员所开发的. Python是荷兰程序员 Guido Van Ro ...
- hadoop手工移块
1.关于磁盘使用策略,介绍参考http://www.it165.net/admin/html/201410/3860.html 在hadoop2.0中,datanode数据副本存放磁盘选择策略有两种方 ...
- 优雅到骨子里的Requests
例子与特性 可以说Requests最大的特性就是其风格的简单直接优雅.无论是请求方法,还是响应结果的处理,还有cookies,url参数,post提交数据,都体现出了这种风格. 以下是一个简单例子: ...
- bupt summer training for 16 #6 ——图论
https://vjudge.net/contest/174020 A.100条双向边,每个点最少连2个边 所以最多100个点,点的标号需要离散化 然后要求恰好经过n条路径 快速幂,乘法过程就是flo ...
- angular的又一本好书
MANNING出的<ANGULAR.JS IN ACTION>. 比上本看完的书<ANGULAR ESSENTIAL>多了一些有全局性的东东. 八个关键概念:MODULE,CO ...
- C#--正则匹配
一个好用的Regex测试插件 快捷键:ctrl+ r , ctrl+ x 打开正则表达式工具 C#的正则表达式的常用的规则: [abc] 里面的每一次字符都可以进行匹配 a{2} 匹配2个a a{2, ...