题目大意:给你$n$个点,求出其中最远点的距离

题解:求出凸包,最远点一定都在凸包上,可以对每条边求出最远的点(可以双指针),然后求出和这条边的端点的距离,更新答案

卡点:最开始对每个点求出最远点,但这样并不可以双指针怎么搞。

C++ Code:

#include <cstdio>
#include <algorithm>
#define maxn 50010
int __X, __Y;
inline int sqr(int x) {return x * x;}
struct Point {
int x, y;
inline Point() {}
inline Point(int __x, int __y) : x(__x), y(__y) {}
inline int abs2() {return sqr(x) + sqr(y);}
inline friend Point operator - (const Point &lhs, const Point &rhs) {
return Point(lhs.x - rhs.x, lhs.y - rhs.y);
}
inline friend Point operator + (const Point &lhs, const Point &rhs) {
return Point(lhs.x + rhs.x, lhs.y + rhs.y);
}
inline friend int operator * (const Point &lhs, const Point &rhs) {
return lhs.x * rhs.y - rhs.x * lhs.y;
}
void writeln() {
printf("(%d, %d)\n", x, y);
}
} O, s[maxn], v[maxn]; inline int abs2(const Point &x) {return sqr(x.x) + sqr(x.y);}
inline int dis2(const Point &lhs, const Point &rhs) {return abs2(lhs - rhs);}
inline int det(const Point O, const Point &lhs, const Point &rhs) {
return (lhs - O) * (rhs - O);
}
inline bool operator < (const Point &lhs, const Point &rhs) {
Point X = lhs - O, Y = rhs - O;
int tmp = X * Y;
return (tmp > 0) || (!tmp && abs2(X) > abs2(Y));
} int n, miny, ans, tot;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &s[i].x, &s[i].y);
if ((s[i].y < s[miny].y) || (s[i].y == s[miny].y && s[i].x < s[miny].x)) miny = i;
}
if (n == 2) {
printf("%d\n", dis2(s[0], s[1]));
return 0;
}
std::swap(s[0], s[miny]);
O.x = s[0].x, O.y = s[0].y;
std::sort(s + 1, s + n);
v[tot++] = s[0], v[tot++] = s[1], v[tot++] = s[2];
for (int i = 3; i < n; i++) {
for (Point a = v[tot - 2], b = v[tot - 1]; tot > 2 && det(a, b, s[i]) <= 0; a = v[tot - 2], b = v[tot - 1]) tot--;
v[tot++] = s[i];
}
int now = 1;
for (int l = 0, r, D, tmp; l < tot; l++) {
r = (l + 1) % tot;
D = det(v[l], v[r], v[now]);
while (D < (tmp = det(v[l], v[r], v[(now + 1) % tot]))) D = tmp, now = (now + 1) % tot;
ans = std::max(ans, std::max(dis2(v[l], v[now]), dis2(v[r], v[now])));
}
printf("%d\n", ans);
return 0;
}

  

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

  1. 洛谷 P1452 Beauty Contest 解题报告

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

  2. 洛谷 P1452 Beauty Contest

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

  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. Shader Forge学习

    最近学习了一下shader forge,一个屌屌哒插件用来生成shader.尽管其降低了制作shader的难度,但是真的想做出满意的shader的话还是得有一定的shader基础.但是仅仅是做出一些简 ...

  2. C if 判断 else 否则

    #include <stdio.h> int main(int argc, char **argv) { //新建三个变量进行比较 int a,b,c; //输入三个变量的值scanf(& ...

  3. 【paging_Class 分页类】使用说明

    类名:paging_Class 说明:分页类 注意: 1) 支持百万级数据分页 2) 支持多种类型的SQL语法,比如 Left Join 等. 3) 自动保存查询中的错误情况,记录保存在:/Cache ...

  4. 【radio-group、radio】 单选项组件说明

    radio-group组件是包裹radio组件的容器 原型: <radio-group bindchange="[EventHandle]"> <radio .. ...

  5. Spring Cloud(十一):服务网关 Zuul(过滤器)【Finchley 版】

    Spring Cloud(十一):服务网关 Zuul(过滤器)[Finchley 版]  发表于 2018-04-23 |  更新于 2018-05-07 |  在上篇文章中我们了解了 Spring ...

  6. 181. Flip Bits【LintCode, by java】

    Description Determine the number of bits required to flip if you want to convert integer n to intege ...

  7. 孤荷凌寒自学python第八十四天搭建jTessBoxEditor来训练tesseract模块

    孤荷凌寒自学python第八十四天搭建jTessBoxEditor来训练tesseract模块 (完整学习过程屏幕记录视频地址在文末) 由于本身tesseract模块针对普通的验证码图片的识别率并不高 ...

  8. Visual Stdio Code编辑Mark Down

    Visual Studio Code可以一边写Markdown一边预览了,而且不需要任何插件. 方法如下: 新建一个文件,以 .md 为后缀: Visual Studio Code 原生就支持高亮Ma ...

  9. solidity中的memory和 storage详解

    Solidity是一种智能合约高级语言,运行在Ethereum虚拟机(EVM)之上.这里我会讲解一下关键字storage和memory的区别. storage的结构是在合约部署创建时,根据你的合约中状 ...

  10. Python3 Tkinter-Scale

    1.创建 from tkinter import * root=Tk() Scale(root).pack() root.mainloop() 2.参数 from tkinter import * r ...