简单的旋转卡壳题目

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

这里求的是距离的平方,所有过程都是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. 3 javascript

    3 javascript javascript基础 html: 负责了一个页面的结构.   css: 负责了一个页面的样式.    javascript: 负责与用户进行交互. 1997年欧洲的计算机 ...

  2. 转:The Knuth-Morris-Pratt Algorithm in my own words

    The Knuth-Morris-Pratt Algorithm in my own words For the past few days, I’ve been reading various ex ...

  3. Linux计划任务入门详解

    Linux操作系统定时任务系统 Cron 入门 cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动 ...

  4. Spring MVC 之文件上传(七)

    SpringMVC同样使用了apache的文件上传组件.所以需要引入以下包: apache-commons-fileupload.jar apache-commons-io.jar 在springAn ...

  5. WCF配置详解

    前面一篇文章<WCF 学习总结1 -- 简单实例> 一股脑儿展示了几种WCF部署方式,其中配置文件(App.config/Web.config)都是IDE自动生成,省去了我们不少功夫.现在 ...

  6. 20160808_安装JDK7u79

    1.将 jdk-7u79-linux-x64.tar.gz 解压,得到文件夹“jdk1.7.0_79” 将 文件夹“jdk1.7.0_79” 复制到 “/usr/java/”下 2.配置环境变量: 文 ...

  7. android中textview设置为多行文本时,如何让文字从最顶开始显示

    <span style="white-space:pre"> </span><EditText android:layout_width=" ...

  8. js倒计时 网上流传最多的

    <!DOCTYPE html><html><head><script src="http://libs.baidu.com/jquery/1.10. ...

  9. azure git 托管

    azure git上传部署步骤:(首次提交)cd 至本地代码路径git initgit add .git commit –m "initial commit"git remote ...

  10. jquery height

    heigth -- 内容高度innerHeight -- 包含padding但不包含borderouterHeight -- 包含borderouterHeight(true) -- 包含margin ...