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

题意

给n个坐标,求最远点对的距离平方值。

分析

模板题,旋转卡壳求求两点间距离平方的最大值。

#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lc idx<<1
#define rc idx<<1|1
#define rson mid+1,r,rc
#define lson l,mid,lc
using namespace std;
typedef long long ll;
template <class T>
void test(T a) {
cout<<a<<endl;
}
template <class T,class T2>
void test(T a,T2 b) {
cout<<a<<" "<<b<<endl;
}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c) {
cout<<a<<" "<<b<<" "<<c<<endl;
}
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = 1e9+;
int T;
void testcase() {
printf("Case %d: ",++T);
}
const int MAXN = ;
const int MAXM = ;
const double PI = acos(-1.0);
const double eps = 1e-; struct Point{
int x,y;
Point(int _x=,int _y=){
x=_x,y=_y;
}
Point operator -(const Point &b)const{
return Point(x-b.x,y-b.y);
}
int operator ^(const Point &b)const{
return x*b.y-y*b.x;
}
int operator *(const Point &b)const{
return x*b.x+y*b.y;
}
void input(){
scanf("%d%d",&x,&y);
}
};
int dis2(Point a,Point b){
return (a-b)*(a-b);
}
Point List[MAXN];
int Stack[MAXN],top;
bool _cmp(Point p1,Point p2){
int tmp=(p1-List[])^(p2-List[]);
if(tmp>) return true;
else if(tmp==&&dis2(p1,List[])<=dis2(p2,List[])) return true;
else return false;
}
void Graham(int n){
Point p0;
int k=;
p0=List[];
for(int i=;i<n;i++){
if(p0.y>List[i].y||(p0.y==List[i].y&&p0.x>List[i].x)){
p0=List[i];
k=i;
}
}
swap(List[k],List[]);
sort(List+,List+n,_cmp);
if(n==){
top=;
Stack[]=;
return;
}
if(n==){
top=;
Stack[]=;
Stack[]=;
return;
}
Stack[]=;
Stack[]=;
top=;
for(int i=;i<n;i++){
while(top>&&((List[Stack[top-]]-List[Stack[top-]])^(List[i]-List[Stack[top-]]))<=)
top--;
Stack[top++]=i;
}
return;
}
int rotating_calipers(Point p[],int n){
int ans=;
Point v;
int cur=;
for(int i=;i<n;i++){
v=p[i]-p[(i+)%n];
while((v^(p[(cur+)%n]-p[cur]))<)
cur=(cur+)%n;
ans=max(ans,max(dis2(p[i],p[cur]),dis2(p[(i+)%n],p[(cur+)%n])));
}
return ans;
}
Point p[MAXN];
int main() {
#ifdef LOCAL
freopen("data.in","r",stdin);
#endif // LOCAL
int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++) List[i].input();
Graham(n);
for(int i=;i<top;i++) p[i]=List[Stack[i]];
printf("%d\n",rotating_calipers(p,top));
}
return ;
}

POJ - 2187 Beauty Contest(最远点对)的更多相关文章

  1. poj 2187 Beauty Contest 最远点距

    /** 求出凸包枚举每个点的矩距离即可 因为凸包上的点可定不多.. 学习: 刚开始WA 了一次,,因为用int 存的, 一看discuss 里提供的数据,想起来,,应该是越界了.. 后来用longlo ...

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

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

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

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

  4. poj 2187 Beauty Contest(平面最远点)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 24431   Accepted: 7459 D ...

  5. POJ 2187 Beauty Contest (求最远点对,凸包+旋转卡壳)

    Beauty Contest Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 24283   Accepted: 7420 D ...

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

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

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

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

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

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

  9. poj 2187 Beauty Contest

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

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

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

随机推荐

  1. mysql 备份数据库 mysqldump

    @echo off for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE ...

  2. CentOS7 卸载mariadb 安装mysql的过程:

    1. 检查安装的mariadb rpm -qa |grep mariadb 得到已经安装的安装包 mariadb-libs-5.5.56-2.el7.x86_64mariadb-devel-5.5.5 ...

  3. live-server

    live-server的安装与使用 初始化npm:npm init 安装live-server:cnpm install -g live-server 根目录启动live-server:live-se ...

  4. Java之JSON操作(Jackson)

    Java to JSON: package json.jackson; import bean.User; import com.fasterxml.jackson.databind.ObjectMa ...

  5. 主成分分析PCA(Principal Component Analysis)在sklearn中的应用及部分源码分析

    最近太忙,又有一段时间没写东西了. pca是机器学习中一个重要的降维技术,是特征提取的代表.关于pca的实现原理,在此不做过多赘述,相关参考书和各大神牛的博客都已经有各种各样的详细介绍. 如需学习相关 ...

  6. 近端梯度算法(Proximal Gradient Descent)

    L1正则化是一种常用的获取稀疏解的手段,同时L1范数也是L0范数的松弛范数.求解L1正则化问题最常用的手段就是通过加速近端梯度算法来实现的. 考虑一个这样的问题: minx  f(x)+λg(x) x ...

  7. BZOJ1906树上的蚂蚁&BZOJ3700发展城市——RMQ求LCA+树链的交

    题目描述 众所周知,Hzwer学长是一名高富帅,他打算投入巨资发展一些小城市. Hzwer打算在城市中开N个宾馆,由于Hzwer非常壕,所以宾馆必须建在空中,但是这样就必须建立宾馆之间的连接通道.机智 ...

  8. BZOJ4455 ZJOI2016小星星(容斥原理+树形dp)

    相当于给树上的每个点分配一个编号使父亲和儿子间都有连边. 于是可以考虑树形dp:设f[i][j][k]为i号点的编号为j,其子树中编号集合为k的方案数.转移显然.然而复杂度3n·n3左右,具体我也不知 ...

  9. BZOJ5294 [BJOI2018] 二进制 【线段树】

    BJOI的题目感觉有点难写 题目分析: 首先推一波结论.接下来的一切都在模3意义下 现在我们将二进制位重组,不难发现的是2^0≡1,2^1≡2,2^2≡1,2^3≡2....所以我们考虑这样的式子 2 ...

  10. MT【72】一个不等式

    证明: 评: 可以思考$\frac{1}{(1+b)^2}+\frac{1}{(1+a)^2}$与$\frac{2}{(1+\sqrt{ab})^2}$大小.