\(\color{#0066ff}{题目描述}\)

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

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

\(\color{#0066ff}{输入格式}\)

第一行:一个整数n

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

\(\color{#0066ff}{输出格式}\)

一行:最远距离的平方

\(\color{#0066ff}{输入样例}\)

4
0 0
0 1
1 1
1 0

\(\color{#0066ff}{输出样例}\)

2

\(\color{#0066ff}{数据范围与提示}\)

none

\(\color{#0066ff}{题解}\)

旋转卡壳的裸题了

先求出凸包

然后枚举凸包上的点,维护单调指针

距离可以通过面积判断(底固定,高最大)

注意,本题有巨坑,居然有一条线的情况,怎么TM求凸包!!!!

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cctype>
#define _ 0
#define LL long long
inline LL in() {
LL x = 0, f = 1; char ch;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
return x * f;
}
const int maxn = 50505;
int n;
struct node {
int x, y;
node(int x = 0, int y = 0)
:x(x), y(y) {}
friend node operator - (const node &a, const node &b) {
return node(a.x - b.x, a.y - b.y);
}
friend int operator ^ (const node &a, const node &b) {
return a.x * b.y - a.y * b.x;
}
int mo() {
return x * x + y * y;
}
double jj() {
return atan2((double)y, (double)x);
}
}e[maxn];
int s[maxn], top; int S(node a, node b, node c) {
return (c - a) ^ (c - b);
} int cmp(node a,node b){
return ((a.jj() < b.jj()) || (a.jj() == b.jj() && (a - e[0]).mo() < (b - e[0]).mo()));
}
void tubao() {
int min = 0;
for(int i = 0; i < n; i++) {
e[i].x = in(), e[i].y = in();
if(e[i].y < e[min].y || (e[i].y == e[min].y && e[i].x < e[min].x)) min = i;
}
std::swap(e[0], e[min]);
for(int i = 1; i < n; i++) e[i] = e[i] - e[0];
e[0] = node(0, 0);
std::sort(e + 1, e + n, cmp);
s[0] = 0, s[1] = 1, s[top = 2] = 2;
for(int i = 3; i < n; i++) {
while(top >= 1 && ((e[s[top]] - e[s[top - 1]]) ^ (e[i] - e[s[top]])) <= 0) top--;
s[++top] = i;
}
}
void rotate() {
s[++top] = s[0];
int ans = 0;
int r = 1;
for(int l = 0; l < top; l++) {
while(S(e[s[l]], e[s[l + 1]], e[s[r + 1]]) > S(e[s[l]], e[s[l + 1]], e[s[r]])) r = (r + 1) % top;
ans = std::max(ans, std::max((e[s[l]] - e[s[r]]).mo(), (e[s[l + 1]] - e[s[r]]).mo()));
}
printf("%d\n", ans);
} signed main() {
n = in();
tubao();
rotate();
return 0;
}

P1452 Beauty Contest 旋转卡壳的更多相关文章

  1. poj2187 Beauty Contest(旋转卡壳)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Beauty Contest Time Limit: 3000MS   Memor ...

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

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

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

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

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

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

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

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

  6. 洛谷 P1452 Beauty Contest 解题报告

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

  7. POJ2187Beauty Contest 旋转卡壳

    题目链接 http://poj.org/problem?id=2187 先求凸包 再求凸多边形直径 旋转卡壳模板题 #include<cstdio> #include<cstring ...

  8. 洛谷 P1452 Beauty Contest

    题目背景 此处省略1W字^ ^ 题目描述 贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”.因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意.世界将被表示成一个二维平面 ...

  9. P1452 Beauty Contest

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

随机推荐

  1. kubernetes 学习 ingress

    ingress是Kubernetes 暴露服务的一种方式. Ingress由两部分组成:Ingress Controller 和 Ingress 服务.     Ingress Contronler ...

  2. CentOS7 线上环境的一些 配置

    上周服务器被攻击导致上面收回了我们服务器的IP,所以这周重新安装部署了服务器,使用centos7系统.为了防止服务器再次被攻击,所以建议以下几点: 1. root密码要复杂一点,尽量字母数字特殊字符都 ...

  3. Python-使用unrar库时Couldn't find path to unrar library的解决办法

    在Pycharm安装完unrar后,还要安装rar官方的库 不然运行的时候会抛出Couldn't find path to unrar library的错误 Windows: 下载rarlib的库文件 ...

  4. PDM后续处理-驼峰规则、清除约束、外键改名

    Option   Explicit ValidationMode   =   True InteractiveMode =   im_Batch Dim   mdl   '当前model '获取当前活 ...

  5. C#数据导出到Excel源代码

    最近工作中需要做一个把用户信息作为excel导出的功能,就顺便整理搜集了一些常用的导出文件的源代码,以供以后不时之需,也希望能给大家带来一些方便 一.DataSet数据集内数据转化为Excel // ...

  6. 解决实现OnPageChangeListener()接口的方法参数出现arg0,arg1的现象

    在安卓开发中,我们经常用到ViewPager,那么既然用到ViewPager,一般都需要去实现OnPageChangeListener()接口的三个方法. 但是有时候实现的三个方法的参数都变成agr0 ...

  7. hadoop job -kill 与 yarn application -kii(作业卡了或作业重复提交或MapReduce任务运行到running job卡住)

    问题详情  解决办法 [hadoop@master ~]$ hadoop job -kill job_1493782088693_0001 DEPRECATED: Use of this script ...

  8. solr replication原理探究

    原文出自:http://sbp810050504.blog.51cto.com/2799422/1423199 无论是垂直搜索,还是通用搜索引擎,对外提供搜索服务其压力都比较大,经常有垂直电商在做活动 ...

  9. php判断终端是手机还是电脑访问网站代码

    ?php function check_wap() { if (isset($_SERVER['HTTP_VIA'])) return true; if (isset($_SERVER['HTTP_X ...

  10. ROS探索总结(五)——创建简单的机器人模型smartcar

    前面我们使用的是已有的机器人模型进行仿真,这一节我们将建立一个简单的智能车机器人smartcar,为后面建立复杂机器人打下基础. 一.创建硬件描述包 roscreat-pkg  smartcar_de ...