●POJ 2187 Beauty Contest
题链:
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的更多相关文章
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- 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 题意:给你一个数据范围在2~5e4范围内的横纵坐标在-1e4~1e4的点,问你任意两点之间的距离的最大值的平方等于多少? 一道卡壳凸包的模板题,也是第一次写计算几何的题, ...
- POJ 2187 Beauty Contest 凸包
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 27276 Accepted: 8432 D ...
- POJ 2187 Beauty Contest [凸包 旋转卡壳]
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36113 Accepted: 11204 ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
- poj 2187:Beauty Contest(旋转卡壳)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 32708 Accepted: 10156 Description Bes ...
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
随机推荐
- Python打包分发工具setuptools
作为Python标准的打包及分发工具,setuptools可以说相当地简单易用.它会随着Python一起安装在你的机器上.你只需写一个简短的setup.py安装文件,就可以将你的Python应用打包 ...
- git基本用法
基本用法(下) 一.实验说明 本节实验为 Git 入门第二个实验,继续练习最常用的git命令. 1.1 实验准备 在进行该实验之前,可以先clone一个练习项目gitproject ...
- Web前端性能分析
Web前端性能通常上代表着一个完全意义上的用户响应时间,包含从开始解析HTML文件到最后渲染完成开始的整个过程,但不包括在输入url之后与服务器的交互阶段.下面是整个过程的各个步骤: 开始解析html ...
- GitChat招募IT类写作作者
GitChat是一个移动端的IT知识.技术分享平台,于2017.10和CSDN合并,成为其旗下独立品牌. 我们正在寻求有互联网基因的人来一起分享IT人员的关切,诚挚邀请您来做一次分享(让IT类文章变现 ...
- JAVA_SE基础——16.方法
接触过C语言的同学,这小章节很容易接受.Java中的方法是类似与C语言中的函数 功能和调用方法都类似 只不过叫法不一样 因为java是面向对象 c是面向过程 仅仅是叫法不同.. . 看到 ...
- 美团点餐—listview内部按钮点击事件
PS:长时间不写博客了,今天来写一下美团的这个点餐界面,今天先写一个加号减号的接口调用,下一篇是整体,有点菜,评价,商家,还有左边的listview和右边的展示项.进入这篇正题,像listview,G ...
- Hadoop安装-部署-测试
一:准备Linux环境[安装略] a.修改主机名 vim /etc/sysconfig/network NETWORKING= ...
- vue-入门
数据绑定 <!--步骤1:创建html文件--> <!DOCTYPE html> <html lang="en"> <head> ...
- 【52ABP实战教程】00-- ASP.NET CORE系列介绍
为什么是.net core? 记得在半年前.NET CORE刚刚出了1.0,当时有朋友推荐我使用的时候,个人觉得还不成熟. 现在.NET Core已经到了2.0,.NET Standard 2.0 添 ...
- leetcode算法:Reshape the Matrix
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new o ...