题链:

http://poj.org/problem?id=2187

题解:

计算几何,凸包,旋转卡壳

一个求凸包直径的裸题,旋转卡壳入门用的。

代码:

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 50050
using namespace std;
const double eps=1e-8;
int sign(double x){
if(fabs(x)<=eps) return 0;
return x<0?-1:1;
}
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y){}
void Read(){scanf("%lf%lf",&x,&y);}
};
typedef Point Vector;
bool operator < (Point A,Point B){return sign(A.x-B.x)<0||(sign(A.x-B.x)==0&&sign(A.y-B.y)<0);}
bool operator == (Point A,Point B){return sign(A.x-B.x)==0&&sign(A.y-B.y)==0;}
Vector operator - (Point A,Point B){return Vector(A.x-B.x,A.y-B.y);}
double operator ^ (Vector A,Vector B){return A.x*B.y-A.y*B.x;}
double operator * (Vector A,Vector B){return A.x*B.x+A.y*B.y;}
Point D[MAXN],C[MAXN];
double GL2(Vector A){//Get_Length^2
return A*A;
}
double DA(Point P,Point P1,Point P2){//Directed_Area
return (P-P1)^(P-P2);
}
int Andrew(int dnt){
int cnt=0,k;
sort(D,D+dnt);
dnt=unique(D,D+dnt)-D;
for(int i=0;i<dnt;i++){
while(cnt>1&&sign((C[cnt-1]-C[cnt-2])^(D[i]-C[cnt-2]))<=0) cnt--;
C[cnt++]=D[i];
} k=cnt;
for(int i=dnt-2;i>=0;i--){
while(cnt>k&&sign((C[cnt-1]-C[cnt-2])^(D[i]-C[cnt-2]))<=0) cnt--;
C[cnt++]=D[i];
}
return cnt-(dnt>1?1:0);
}
double RC_GD(int hnt){//Rotating_Calipers_Get_Diameter
if(hnt==1) return 0;
if(hnt==2) return GL2(C[1]-C[0]);
double Di=0; int j=0; C[hnt]=C[0];
for(int i=0;i<hnt;i++){
while(sign(DA(C[j],C[i],C[i+1])-DA(C[j+1],C[i],C[i+1])<=0)) j=(j+1)%hnt;
Di=max(Di,GL2(C[j]-C[i])); Di=max(Di,GL2(C[j]-C[i+1]));
}
return Di;
}
int main(){
int N; scanf("%d",&N);
for(int i=0;i<N;i++)
D[i].Read();
printf("%d",(int)RC_GD(Andrew(N)));
return 0;
}

  

●POJ 2187 Beauty Contest的更多相关文章

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

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

  2. poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)

    链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...

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

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

  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 题意:给你一个数据范围在2~5e4范围内的横纵坐标在-1e4~1e4的点,问你任意两点之间的距离的最大值的平方等于多少? 一道卡壳凸包的模板题,也是第一次写计算几何的题, ...

  6. POJ 2187 Beauty Contest 凸包

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

  7. POJ 2187 Beauty Contest [凸包 旋转卡壳]

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 36113   Accepted: 11204 ...

  8. POJ 2187 Beauty Contest(凸包,旋转卡壳)

    题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...

  9. poj 2187:Beauty Contest(旋转卡壳)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32708   Accepted: 10156 Description Bes ...

  10. POJ 2187 Beauty Contest(凸包+旋转卡壳)

    Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...

随机推荐

  1. Django 个性化管理员站点

    from django.contrib import admin # Register your models here. from .models import Moment class Momen ...

  2. EL表达式 与 servlvet3.0的新规范

    EL表达式 EL表达式 是一种简化的数据访问方式,是对jsp脚本的简化  . 如我们在一个页面中需要输出session的保存的一个值: <%  out.println(session.getAt ...

  3. vue项目结构

    前言 我在 搭建vue项目环境 简单说明了项目初始化完成后的目录结构. 但在实际项目中,src目录下的结构需要跟随项目做一些小小的调整. 目录结构 ├── src 项目源码目录 │ ├── api 所 ...

  4. 基于ssm的poi反射bean实例

    一:该例子是笔者在实际项目应用过程中,针对项目完成的一套基于poi的导入导出例子,其中一些与项目有关的代码大家直接替换成自己的需求即可. 二:笔者在项目中使用的是poi的XSSF,对应maven的po ...

  5. java之servlet小记

    Servlet               service+applet                   服务+小程序 Java是语言,像c\c#等一样,是一门计算机语言,servlet是java ...

  6. WPF 自定义ItemsControl/ListBox/ListView控件样式

    一.前言 ItemsControl.ListBox.ListView这三种控件在WPF中都可作为列表信息展示控件.我们可以通过修改这三个控件的样式来展示我们的列表信息. 既然都是展示列表信息的控件,那 ...

  7. [扩展推荐] —— Laravel Log 增强

    Laravel Log Enhancer 是 Laravel 5.6  的一个扩展包,可以在 Laravel 日志中添加额外的数据. 得益于 Laravel 5.6 中日志的更新,这个包利用这些特性扩 ...

  8. Linux进程管理:后台启动进程和任务管理命令

    一.为什么要使程序在后台执行 我们的应用有时候要运行时间很长,如:几个小时甚至几个星期,我们可以让程序在后台一直跑. 让程序在后台运行的好处有: 终端关机不影响后台进程的运行.(不会终端一关机或者网络 ...

  9. JavaScript 以及 css3进度条

    JavaScript css3进度条 使用css3实现进度条 <!DOCTYPE html> <html lang="en"> <head> & ...

  10. requests-证书验证

    import requests #response = requests.get('https://www.12306.cn') #print(response.status_code) #以上会显示 ...