链接

利用旋转卡壳

参考博客http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 50010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
int x,y;
point(int x=,int y = ):x(x),y(y){}
}p[N],ch[N];
typedef point pointt;
pointt operator - (point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double cross(point a,point b)
{
return 1.0*a.x*b.y-a.y*b.x;
}
double mul(point p0,point p1,point p2)
{
return cross(p1-p0,p2-p0);
}
int dis(point a)
{
return a.x*a.x+a.y*a.y;
}
bool cmp(point a,point b)
{
if(dcmp(mul(p[],a,b))==) return dis(a-p[])<dis(b-p[]);
return dcmp(mul(p[],a,b))>;
}
int graham(int n)
{
int i,k=,top;
point tmp;
for(i = ; i< n; i++)
{
if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))
k = i;
}
if(k!=)
swap(p[],p[k]);
sort(p+,p+n,cmp);
ch[] = p[];
ch[] = p[];
top = ;
for(i = ; i < n; i++)
{
while(top>&&dcmp(mul(ch[top-],ch[top],p[i]))<=)
top--;
ch[++top] = p[i];
}
return top;
}
int rotating_calipers(int n)
{
int q = ;
int ans = ;
ch[n] = ch[];
for(int i = ; i < n; i++)
{
while(mul(ch[i+],ch[q+],ch[i])>mul(ch[i+],ch[q],ch[i]))
q = (q+)%n;
ans = max(ans,max(dis(ch[i]-ch[q]),dis(ch[i+]-ch[q+])));
}
return ans;
}
int main()
{
int n,i;
while(scanf("%d",&n)!=EOF)
{
for(i = ; i < n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
int top = graham(n);
int ans = rotating_calipers(top+);
printf("%d\n",ans);
}
return ;
}

poj2187Beauty Contest(凸包直径)的更多相关文章

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

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

  2. 【POJ 2187】Beauty Contest(凸包直径、旋转卡壳)

    给定点集的最远两点的距离. 先用graham求凸包.旋(xuán)转(zhuàn)卡(qiǎ)壳(ké)求凸包直径. ps:旋转卡壳算法的典型运用 http://blog.csdn.net/hanch ...

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

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

  4. UVa 1453 - Squares 旋转卡壳求凸包直径

    旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...

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

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

  6. POJ2187Beauty Contest(任意点的最远距离 + 凸包)

    题目链接 题意:就是给N个点的坐标,然后求任意两个点距离的平方最大的值 枚举超时. 当明白了 最远距离的两个点一定在凸包上,一切就好办了.求出凸包,然后枚举 #include <iostream ...

  7. POJ 3384 Feng Shui 凸包直径 + 半平面交

    G++一直没有过了 换成 C++果断A掉了...It's time to bet RP. 题意:给一个多边形,然后放进去两个圆,让两个圆的覆盖面积尽量最大,输出两个圆心的坐标. 思路:将多边形的边向里 ...

  8. POJ 2187 Beauty Contest 凸包

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 27276   Accepted: 8432 D ...

  9. POJ2187Beauty Contest 旋转卡壳

    题目链接 http://poj.org/problem?id=2187 先求凸包 再求凸多边形直径 旋转卡壳模板题 #include<cstdio> #include<cstring ...

随机推荐

  1. Codeforces 741B:Arpa's weak amphitheater and Mehrdad's valuable Hoses(01背包+并查集)

    http://codeforces.com/contest/741/problem/B 题意:有 n 个人,每个人有一个花费 w[i] 和价值 b[i],给出 m 条边,代表第 i 和 j 个人是一个 ...

  2. sql截断日志

    --收缩数据库 DBCC SHRINKDATABASE(fas) --截断事务日志: BACKUP LOG fas WITH NO_LOG 1.清空日志 DUMP TRANSACTION 库名 WIT ...

  3. 【转】Program Files (x86)文件夹是干什么的

    转载地址:http://leonax.net/p/2373/what-program-files-x86-folder-for/ 今天在微博上看到有人问这个问题.在装好64位的Windows之后,能在 ...

  4. 【转】JAVA变量path , classpth ,java_home设设置作用和作用

    转载地址:http://bbs.tech.163.com/bbs/tech_0ik1/147645925.html 在把jdk安装到计算机中之后,我们来进行设置使java环境能够使用. 首先右键点我的 ...

  5. 理解 Android Build 系统

    在配置了以上的文件之后,便可以编译出我们新添加的设备的系统镜像了. 首先,调用“source build/envsetup.sh”该命令的输出中会看到 Build 系统已经引入了刚刚添加的 vendo ...

  6. ds.Merge 与 ds.Tables[0].Merge 的用法

    DataSet ds = new DataSet(); SqlConnection conn = new SqlConnection(ConnectionStr);            SqlCom ...

  7. JAVA基础知识之多线程——线程池

    线程池概念 操作系统或者JVM创建一个线程以及销毁一个线程都需要消耗CPU资源,如果创建或者销毁线程的消耗源远远小于执行一个线程的消耗,则可以忽略不计,但是基本相等或者大于执行线程的消耗,而且需要创建 ...

  8. Combox控件初始化项的技巧

    有时候combox下拉项就是几条固定的,不需要做数据绑定,但是如果直接采用字符串集合编辑器的时候,SelectedValue貌似会不起作用. 于是简单的封装一下 /// <summary> ...

  9. 同一服务器部署多个tomcat时的端口号修改详情

    同一服务器部署多个tomcat时,存在端口号冲突的问题,所以需要修改tomcat配置文件server.xml,以tomcat7为例. 首先了解下tomcat的几个主要端口: <Connector ...

  10. Android的BroadcastReceiver 广播 短信拦截

    如何去理解BroadcastReceiver(广播)?其实可以这样想,首先我们要有一个发送广播的"媒体",在这个例子中,我们暂且用activity组件作为这个媒体,当然以后会用到s ...