题目背景

此处省略1W字^ ^

题目描述

贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”。因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意。世界将被表示成一个二维平面,每个农场位于一对整数坐标(x,y),各有一个值范围在-10000…10000。没有两个农场共享相同的一对坐标。

尽管贝西沿直线前往下一个农场,但牧场之间的距离可能很大,所以她需要一个手提箱保证在每一段旅程中她有足够吃的食物。她想确定她可能需要旅行的最大可能距离,她要知道她必须带的手提箱的大小。帮助贝西计算农场的最大距离。

输入输出格式

输入格式:

第一行:一个整数n

第2~n+1行:xi yi 表示n个农场中第i个的坐标

输出格式:

一行:最远距离的[b]平方[/b]

输入输出样例

输入样例#1:

4
0 0
0 1
1 1
1 0
输出样例#1:

2

说明

NONE

旋转卡壳模板题,求个凸包之后用叉积求出离当期枚举直线的最远点(肯定是单调变化的)

/*
排序一定要严格按x第一关键字,y第二关键字升序排序,,,
不然后果就是WA一墙调半天不知道哪错的hhhh
*/
#include<bits/stdc++.h>
#define ll long long
#define maxn 50005
using namespace std;
const double eps=0.000000001; inline int zt(double x){
if(fabs(x)<=eps) return ;
return (x>?:-);
} inline double sq(double x){
return x*x;
} struct node{
double x,y; node operator +(const node& u)const{
return (node){x+u.x,y+u.y};
} node operator -(const node& u)const{
return (node){x-u.x,y-u.y};
} node operator *(const double& u)const{
return (node){x*u,y*u};
} bool operator <(const node& u)const{
return zt(x-u.x)?zt(x-u.x)<:zt(y-u.y)<;
}
}a[maxn],q[maxn],ret[maxn]; inline double ptmul(node x,node y){
return x.x*y.x+x.y*y.y;
} inline double Xmul(node x,node y){
return x.x*y.y-x.y*y.x;
} inline bool eq(node x,node y){
return (!zt(x.x-y.x)&&!zt(x.y-y.y));
} inline double dist(node x,node y){
return sq(x.x-y.x)+sq(x.y-y.y);
} inline int get_hill(node *u,int len){
sort(u+,u+len+); int tt=,tot=;
q[]=u[],q[]=u[];
for(int i=;i<=len;i++){
while(tt>&&zt(Xmul(q[tt]-q[tt-],u[i]-q[tt]))<) tt--;
q[++tt]=u[i];
}
for(int i=;i<=tt;i++) ret[++tot]=q[i]; tt=;
q[]=u[],q[]=u[];
for(int i=;i<=len;i++){
while(tt>&&zt(Xmul(q[tt]-q[tt-],u[i]-q[tt]))>) tt--;
q[++tt]=u[i];
}
int pre=tot;
for(int i=tt;i;i--) if(!eq(q[i],ret[])&&!eq(q[i],ret[pre])) ret[++tot]=q[i]; for(int i=;i<=tot;i++) u[i]=ret[i];
return tot;
} int n;
double ans=; inline void solve(){
node r=a[]-a[n];
int pt=,nxt=; while(zt(fabs(Xmul(r,a[nxt]-a[n]))-fabs(Xmul(r,a[pt]-a[n])))>){
pt=nxt,nxt++;
if(nxt>n) nxt-=n;
}
ans=max(ans,max(dist(a[],a[pt]),dist(a[n],a[pt]))); for(int i=;i<n;i++){
r=a[i+]-a[i];
while(zt(fabs(Xmul(r,a[nxt]-a[i]))-fabs(Xmul(r,a[pt]-a[i])))>){
pt=nxt,nxt++;
if(nxt>n) nxt-=n;
}
ans=max(ans,max(dist(a[i],a[pt]),dist(a[i+],a[pt])));
} } int main(){
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y); n=get_hill(a,n); solve(); printf("%.0lf\n",ans);
return ;
}

洛谷 P1452 Beauty Contest的更多相关文章

  1. 洛谷 P1452 Beauty Contest 解题报告

    P1452 Beauty Contest 题意 求平面\(n(\le 50000)\)个点的最远点对 收获了一堆计算几何的卡点.. 凸包如果不保留共线的点,在加入上凸壳时搞一个相对栈顶,以免把\(n\ ...

  2. [洛谷P1452]Beauty Contest

    题目大意:给你$n$个点,求出其中最远点的距离 题解:求出凸包,最远点一定都在凸包上,可以对每条边求出最远的点(可以双指针),然后求出和这条边的端点的距离,更新答案 卡点:最开始对每个点求出最远点,但 ...

  3. 【洛谷 P1452】 Beauty Contest (二维凸包,旋转卡壳)

    题目链接 旋转卡壳模板题把. 有时间再补总结吧. #include <cstdio> #include <cmath> #include <algorithm> u ...

  4. 洛谷P4645 [COCI2006-2007 Contest#7] BICIKLI [Tarjan,拓扑排序]

    题目传送门 BICIKLI 题意翻译 给定一个有向图,n个点,m条边.请问,1号点到2号点有多少条路径?如果有无限多条,输出inf,如果有限,输出答案模10^9的余数. 两点之间可能有重边,需要看成是 ...

  5. P1452 Beauty Contest 旋转卡壳

    \(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...

  6. P1452 Beauty Contest

    传送门 求凸包周长,用旋转卡壳,具体可见yyb大佬的博客 顺便一提这题暴力+随机化也能过 暴力代码 //minamoto #include<bits/stdc++.h> #define r ...

  7. 洛谷P4891 序列 || 膜法阵,魔法阵

    https://www.luogu.org/problemnew/show/P4891 一道几乎一样的题http://210.33.19.103/contest/1130/problem/3 题面ht ...

  8. Guard Duty (medium) Codeforces - 958E2 || (bzoj 2151||洛谷P1792) 种树 || 编译优化

    https://codeforces.com/contest/958/problem/E2 首先求出N个时刻的N-1个间隔长度,问题就相当于在这些间隔中选K个数,相邻两个不能同时选,要求和最小 方法1 ...

  9. BZOJ 1901 洛谷 P2617 ZOJ 2112 Dynamic Rankings

    以下时空限制来自zoj Time limit 10000 ms Memory limit 32768 kB OS Linux Source Online Contest of Christopher' ...

随机推荐

  1. PHP 5.4语法改进与弃用特性

    PHP 5.4于本月尘埃落定,它是 PHP 自 2009 年以来的首次重大更新.该版本对语言部分进行了增强,包括支持 Traits 和移除部分争议特性. Traits 同 Java 和 .NET 一样 ...

  2. git使用笔记(七)版本回退和撤销

    By francis_hao    Nov 21,2016 从版本库初始化开始,每一步的撤销操作 添加第一个文件 在空的版本库中创建了一个文件并git add到了缓存区,这时候怎么撤销呢? 撤销单个文 ...

  3. MySQL 数据库性能优化之缓存参数优化

    在平时被问及最多的问题就是关于 MySQL 数据库性能优化方面的问题,所以最近打算写一个MySQL数据库性能优化方面的系列文章,希望对初中级 MySQL DBA 以及其他对 MySQL 性能优化感兴趣 ...

  4. Swift开发学习(一):初始篇

    http://blog.csdn.net/powerlly/article/details/29351103 Swift开发学习:初始篇 关于 苹果公司于WWDC2014(Apple Worldwid ...

  5. System and method for parallel execution of memory transactions using multiple memory models, including SSO, TSO, PSO and RMO

    A data processor supports the use of multiple memory models by computer programs. At a device extern ...

  6. guake终端复制标签页

    平时习惯用的终端是下拉式终端guake,开多个标签各司其职,热键一按,呼之即来,挥之即去. 但用一个东西,就难免会有不爽的地方,比如每次想复制一个标签页,就要3步,1 新建标签页, 2 切换到之前的路 ...

  7. UVALIVE 3486 Cells

    通过入栈出栈顺序判断祖先关系 这里UVALIVE还 #include <map> #include <set> #include <list> #include & ...

  8. Linux服务器中OpenSSH的源码编译与升级

                      Linux服务器中OpenSSH的源码编译与升级 https://www.oschina.net/question/12_7383    

  9. 开源的zip_unzip库

    zip/unzip源码交叉编译 http://blog.chinaunix.net/uid-20288609-id-10016.html zlib 1.2.11 http://www.zlib.net ...

  10. Python标准库——collections模块的Counter类

    1.collections模块 collections模块自Python 2.4版本开始被引入,包含了dict.set.list.tuple以外的一些特殊的容器类型,分别是: OrderedDict类 ...