题目大意:给你$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. javaweb(六)——Servlet开发(二)

    一.ServletConfig讲解 1.1.配置Servlet初始化参数 在Servlet的配置文件web.xml中,可以使用一个或多个<init-param>标签为servlet配置一些 ...

  2. CentOS 7.2静默安装Oracle11g

      Preface       Today I'm gonna export some test data to another server.The source server is Windows ...

  3. python 水仙花

    #简单def narcissus(): for n in range(100, 1000, 1): a, b, c = n//100, (n//10)%10, (n%100)%10 if a ** 3 ...

  4. apache+php开发环境搭建步骤

    apache 卸载apache服务命令:sc delete apache 1.在D盘下面新建文件夹php7 2.解压apache到php7文件夹下面 3.修改配置文件 4.安装apache服务C:\w ...

  5. 180612-Spring之Yml配置文件加载问题

    Yml配置文件加载问题 在resource目录下有一个application.yml文件,希望是通过@PropertySource注解,将配置文件数据读取到Environment中,然而调试发现数据始 ...

  6. PAT - L2-001. 紧急救援( Dijstra )

    - PAT - L2-001. 紧急救援 题目链接 作为一个城市的应急救援队伍的负责人,你有一张特殊的全国地图.在地图上显示有多个分散的城市和一些连接城市的快速道路.每个城市的救援队数量和每一条连接两 ...

  7. leetcode-零钱兑换—int溢出

     零钱兑换 给定不同面额的硬币 coins 和一个总金额 amount.编写一个函数来计算可以凑成总金额所需的最少的硬币个数.如果没有任何一种硬币组合能组成总金额,返回 -1. 示例 1: 输入: c ...

  8. LinQ to SQL 及 non-LinQ方式实现Group的Performance对比

    拥有476550数据的一张数据表.使用其中的某个字段分组,然后按该字段进行排序.该需求分别使用LinQ to SQL和non-LinQ的方式实现,然后来看一下performance对比. LinQ w ...

  9. 【转载】inotify+rsync实时同步 解决同步慢问题 (转载备记)

    原文地址:http://www.ttlsa.com/web/let-infotify-rsync-fast/ 背景 我们公司在用inotify+rsync做实时同步,来解决分布式集群文件一致性的问题. ...

  10. 20145214 《Java程序设计》第4周学习总结

    20145214 <Java程序设计>第4周学习总结 教材学习内容总结 继承 继承基本上就是避免多个类间重复定义共同行为.要避免在程序设计上出现重复,可以把相同的程序代码提升为父类. 关键 ...