POJ 2187 求凸包上最长距离
简单的旋转卡壳题目
以每一条边作为基础,找到那个最远的对踵点,计算所有对踵点的点对距离
这里求的是距离的平方,所有过程都是int即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 50010
#define eps 1e-9
int n , top; int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
} struct Point{
int x,y;
Point(int x= , int y=):x(x),y(y){}
bool operator==(const Point &m) const{
return x==m.x&&y==m.y;
}
int squaredDis(){return x*x+y*y;}
void input(){scanf("%d%d" , &x , &y);}
void print(){cout<<x<<" "<<y<<endl;}
}po[N] , rec[N] , p;
typedef Point Vector; Vector operator+(Vector a , Vector b){return Vector(a.x+b.x , a.y+b.y);}
Vector operator-(Vector a , Vector b){return Vector(a.x-b.x , a.y-b.y);}
Vector operator*(Vector a , double b){return Vector(a.x*b , a.y*b);}
Vector operator/(Vector a , double b){return Vector(a.x/b , a.y/b);} int Cross(Vector a , Vector b){return a.x*b.y-b.x*a.y;}
double Len(Vector a){return sqrt(a.x*a.x*1.0+a.y*a.y);} bool cmp(Point a , Point b){
int v = Cross(a , b);
if(v == ) return a.x<b.x;
else return v>;
} void Graham(Point *a , Point *rec)
{
sort(a , a+n , cmp);
// for(int i=0 ; i<n ; i++) cout<<i<<" "<<a[i].x<< " "<<a[i].y<<endl;
rec[] = a[] , rec[] = a[];
top=;
for(int i= ; i<n ; i++){
while(top> && Cross(rec[top]-rec[top-] , a[i]-rec[top-])<=)
top--;
rec[++top] = a[i];
}
// for(int i=0 ; i<=top ; i++) cout<<i<<" "<<rec[i].x<< " "<<rec[i].y<<endl;
int tmp = top;
for(int i=n- ; i>= ; i--){
while(top>tmp && Cross(rec[top]-rec[top-] , a[i]-rec[top-])<=)
top--;
rec[++top]=a[i];
}
// for(int i=0 ; i<=top ; i++) cout<<i<<" "<<rec[i].x<< " "<<rec[i].y<<endl;
} int maxDis(Point *a)
{
int la=top- , p= , q=;
int maxn = ;
for(p= ; p<top ; p++){
while(Cross(a[p]-a[la] , a[q+]-a[la]) - Cross(a[p]-a[la] , a[q]-a[la])>)
q=(q+)%top;
maxn = max(maxn , (a[q]-a[la]).squaredDis());
maxn = max(maxn , (a[q]-a[p]).squaredDis());
la = p;
}
return maxn;
} int main()
{
// freopen("a.in" , "r" , stdin);
while(~scanf("%d" , &n))
{
for(int i= ; i<n ; i++) po[i].input();
p = po[];
for(int i= ;i<n ; i++)
if(po[i].y<p.y||(po[i].y==p.y&&po[i].x<p.x)) p=po[i];
Graham(po , rec);
int ans = maxDis(rec);
cout<<ans<<endl;
}
return ;
}
POJ 2187 求凸包上最长距离的更多相关文章
- poj 3525 求凸包的最大内切圆
Most Distant Point from the Sea Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3640 ...
- POJ 1118 求平面上最多x点共线
题意:给你n个点的坐标.求一条直线最多能穿过多少个点. 思路:枚举(n^2)+求斜率+排序 (复杂度n^2logn)大功告成 //By: Sirius_Ren #include <cmath&g ...
- POJ 2187 /// 凸包入门 旋转卡壳
题目大意: 求最远点对距离 求凸包上的最远点对 挑战263页 #include <cstdio> #include <string.h> #include <algori ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 2187:Beauty Contest(计算几何,求凸包,最远点对)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26180 Accepted: 8081 D ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- poj 2187 凸包加旋转卡壳算法
题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
随机推荐
- UEditor 之查询当前编辑区域的状态是源码模式还是可视化模式
在使用百度的编辑器的时候,遇到了这样的一个问题: 解决方法是 使用了两个命令:
- 垂直的seekbar
看下效果: 1 package org.qianyukun.core.views; import android.content.Context; import android.graphics.Ca ...
- VC++编译GSL
目录 第1章 VC++ 1 1.1 修改行结束符 1 1.2 修改#include "*.c" 为 #include "*.inl" 2 1. ...
- MM--发票校验 及基于采购订单的MIRO发票校验过程(
一.介绍发票校验是物料管理(MM)系统的一部分.它提供物料管理部分和财务会计, 成本控制和资产管理部分的连接.物料管理模块的发票校验为以下目的服务:它完成物料采购的全过程 - 物料采购从采购申请开始, ...
- 配置electron
配置语句: git clone https://github.com/electron/electron-quick-start 文件夹名字 打开该文件(我用的webstorm)
- IE7浏览器下CSS属性选择器二三事
一.为何专门说起IE7 以前,或者说数年前,我们从事桌面端网页开发的时候,基本上都还要兼顾IE6浏览器, 即使有些特性,IE7支持,我们也会忽略之.于是,我们会不自然地把IE6和IE7浏览器归为一路货 ...
- jmeter笔记6
一.图形报表 图表底部参数的含义如下: 样本数目是总共发送到服务器的请求数. 最新样本是代表时间的数字,是服务器响应最后一个请求的时间. 吞吐量是服务器每分钟处理的请求数. 平均值是总运行时间 ...
- Intellij IDEA中部署Tomcat报错“war exploded: Server is not connected. Deploy is not available”
最近将本机的Tomcat 7卸载重装了Tomcat 9后,在IDEA中运行Tomcat老是报错,一直未找到解决问题的办法. 只能讲Tomcat重新退回到版本7,才重新再IDEA中运行正常.
- python读取指定内存的内容
import ctypes as ct t = ct.string_at(0x211000, 20) # (addr, size) print t 最好不要用解释性语言来开发底层,一般用C.
- JQ添加移除css样式
1. addClass() - 添加CSS类 $("#target").addClass("newClass"); //#target 指的是需要添加样式的元素 ...