\(\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;
}

最新文章

  1. cnetos7.0 安装mysql
  2. DEDE 常用的调用方法
  3. css简单评论页面
  4. 分享:关于之前锤子手机刷MIUI之后,现在有事跌宕起伏的刷回了Smartisan OS!
  5. iOS开发——高级篇——地图 MapKit
  6. maketrans translate
  7. HttpURLConnection请求网络数据
  8. centos6.4搭建knowlededgeroot-1.0.4知识库平台
  9. linux下配置tomcat7 + solr4.9
  10. redis常见性能问题和解决方案?
  11. 怎样检查手机是否root成功
  12. android点滴之PendingIntent的使用
  13. 转载:ecshop自定义销量
  14. 04-创建kubeconfig认证文件
  15. ajax 常用功能 结构分解
  16. 如何往有自增标识字段的表插入数据时,同时给自增标识字段插入值呢,在Inset Into语句前后加上SQL语句:SET IDENTITY_INSERT TableName ON和SET IDENTITY_INSERT TableName OFF
  17. Mysql服务配置优化
  18. [C++]指针与引用(应用辨析)
  19. PHP在linux读取word文档
  20. windows进程中的几个杂项-hpguard 进程终止

热门文章

  1. 我和domino不得不说的故事(连载2016-3-2)
  2. [置顶] 制作开机LOGO就是这么简单!
  3. Rails上传文件
  4. js实现大文件分片上传的方法
  5. centos7的xfs配置
  6. C++深度解析教程学习笔记(1)C到C++的升级
  7. div盒子模型
  8. Tornado之抽屉实战(2)--数据库表设计
  9. actionbar中添加searchview并监听期伸缩/打开的方法
  10. day70-oracle 12-触发器