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

学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738

https://www.jianshu.com/p/74c25c0772d6

注意求凸包时先下后上,保持逆时针;

别忘了给点排序囧。

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int const xn=;
int n,tot,ans;
struct P{
int x,y;
P(int x=,int y=):x(x),y(y) {}
bool operator < (const P &b) const
{return x<b.x||(x==b.x&&y<b.y);}
}p[xn],c[xn];
P operator - (const P &a,const P &b){return P(a.x-b.x,a.y-b.y);}
int cross(P a,P b){return a.x*b.y-a.y*b.x;}
int maxx(int x,int y){return x<y?y:x;}
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
void find()
{
sort(p+,p+n+);//!
for(int i=;i<=n;i++)//under
{
while(tot>&&cross(c[tot]-c[tot-],p[i]-c[tot])<=)tot--;
c[++tot]=p[i];
}
int num=tot;
for(int i=n-;i;i--)//top
{
while(tot>num&&cross(c[tot]-c[tot-],p[i]-c[tot])<=)tot--;
c[++tot]=p[i];
}
tot--;//p[1]
}
int sqr(int x){return x*x;}
int disq(P a,P b){return sqr(a.x-b.x)+sqr(a.y-b.y);}
void work()
{
ans=disq(c[],c[]); c[tot+]=c[];
for(int i=,p=;i<=tot;i++)
{
while(cross(c[p]-c[i],c[p]-c[i+])<cross(c[p+]-c[i],c[p+]-c[i+]))
{p++; if(p==tot+)p=;}
ans=maxx(ans,maxx(disq(c[p],c[i]),disq(c[p+],c[i+])));
}
}
int main()
{
n=rd();
for(int i=;i<=n;i++)p[i].x=rd(),p[i].y=rd();
find(); work();
printf("%d\n",ans);
return ;
}

poj 2187 Beauty Contest —— 旋转卡壳的更多相关文章

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

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

  2. poj 2187 Beauty Contest——旋转卡壳

    题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  3. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

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

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

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

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

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

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

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

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

  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(凸包+旋转卡壳)

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

随机推荐

  1. sql 语句实现分页查询

    SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT * FROM TABLE_NAME) A WHERE ROWNUM <= 40 ) WHER ...

  2. git本地仓库管理远程仓库

    git remote add origin https://xxxxxgit push -u origin master

  3. dva+antd写的一个react例子--服务器nginx 的配置

    location ^~ /crm { rewrite ^/crm/(.*)(\.js|\.css|\.png|\.jpg|\.jpeg|\.gif|index\.php|robots\.txt)$ / ...

  4. Android TextView文字过多时通过滚动条显示多余内容

    方法一: TextView文字过多,显示不全,怎么办?我们可以为Textview添加滚动条. <TextView android:id="@+id/bus_detail_content ...

  5. 2018年长沙理工大学第十三届程序设计竞赛 G 逃离迷宫 【BFS】

    链接:https://www.nowcoder.com/acm/contest/96/G 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  6. Data Structure Array: Move all zeroes to end of array

    http://www.geeksforgeeks.org/move-zeroes-end-array/ #include <iostream> #include <vector> ...

  7. 【leetcode刷题笔记】Jump Game II

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. Python 3 mysql 简介安装

    Python 3 mysql 简介安装 一.数据库是什么 1.  什么是数据库(DataBase,简称DB) 数据库(database,DB)是指长期存储在计算机内的,有组织,可共享的数据的集合.数据 ...

  9. vary的用法

    对于vary的用法,网上有许多种说法,云里雾里的,在此仅阐述一下本人的一些理解,首先是官方解释: Vary头域值指定了一些请求头域,这些请求头域用来决定: 当缓存中存在一个响应,并且该缓存没有过期失效 ...

  10. 第一篇 css导入方式 及选择器

    一 推荐资料 推荐书籍 css Zen Garden 中文(css禅意花园) 二.css样式 1.css样式表特征 继承性  大多数css的样式规则可以被继承 层叠性 1)可以定义 多个样式 2)不冲 ...