简单的旋转卡壳题目

以每一条边作为基础,找到那个最远的对踵点,计算所有对踵点的点对距离

这里求的是距离的平方,所有过程都是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 求凸包上最长距离的更多相关文章

  1. poj 3525 求凸包的最大内切圆

    Most Distant Point from the Sea Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3640   ...

  2. POJ 1118 求平面上最多x点共线

    题意:给你n个点的坐标.求一条直线最多能穿过多少个点. 思路:枚举(n^2)+求斜率+排序 (复杂度n^2logn)大功告成 //By: Sirius_Ren #include <cmath&g ...

  3. POJ 2187 /// 凸包入门 旋转卡壳

    题目大意: 求最远点对距离 求凸包上的最远点对 挑战263页 #include <cstdio> #include <string.h> #include <algori ...

  4. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  5. poj 2187:Beauty Contest(计算几何,求凸包,最远点对)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 26180   Accepted: 8081 D ...

  6. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  7. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  8. poj 2187 凸包加旋转卡壳算法

    题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...

  9. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

随机推荐

  1. 反演dp经典

    咋一看,至少要用3^n才能做到. 但. 首先定义: 可以发现只要求出a' b' 那么直接可以得出c' 那么如何求a'呢 //dp求a',其实就是分别用[0,n)来更新a' ; i < n; i+ ...

  2. 修改Mac]Bringing interface etch0:Device

    OS版本:Red Hat Enterprise Linux AS4/5 网上有很多关于linux下修改MAC地址的方法,大多依葫芦画瓢,似乎都没验证过,达不到修改的目的. 经过我的详细测试,最终成功解 ...

  3. laravel 中 与前端的一些事1

    首先安装node.js 在命令行中敲node -v 可以查看node的版本信息 还需要安装npm,相当于php中的composer node.js中5.0版本后的都已经将npm打包进node了 还要安 ...

  4. Java Swing事件处理机制

    Java Swing的事件处理机制 Swing GUI启动后,Java虚拟机就启动三个线程,分别为主线程,事件派发线程(也是事件处理线程)和系统工具包线程. 主线程 :负责创建并显示该程序的初始界面: ...

  5. IE和主流浏览器

    1.添加事件 addEventListener 主流 attachEvent     IE 2.移除事件 removeEventListener detachEvent 3.获取事件对象 event ...

  6. robot API笔记2

    robot.conf 设计方案 实现设置测试执行和输出处理. 这个方案实现了 RobotSettings 和 RebotSettings 内部使用的类 该框架. 不应该有这些类需要使用外部.这个包可以 ...

  7. 《javascript高级程序设计》 第24章 最佳实践 Best Practices

    24.1 可维护性 Maintainability24.1.1 什么是可维护的代码 What Is Maintainable Code?24.1.2 代码约定 Code Conventions 24. ...

  8. memset,memcpy,memcmp用法

    void* memset(void *s, int ch, size_t n); 将s所指向的某一块内存中的前n个字节的内容全部设置为ch指定的ASCII值. 例如:memset(lpMyStruct ...

  9. Python中一些内建函数及os等模块的用法

          len(obj)                   # 求长度:obj可以是str.list等对象    split(str, num)          # str-分割符,默认空格: ...

  10. Binary Tree Level Order Traversal [LeetCode]

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...