[洛谷P1452]Beauty Contest
题目大意:给你$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的更多相关文章
- 洛谷 P1452 Beauty Contest 解题报告
P1452 Beauty Contest 题意 求平面\(n(\le 50000)\)个点的最远点对 收获了一堆计算几何的卡点.. 凸包如果不保留共线的点,在加入上凸壳时搞一个相对栈顶,以免把\(n\ ...
- 洛谷 P1452 Beauty Contest
题目背景 此处省略1W字^ ^ 题目描述 贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”.因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意.世界将被表示成一个二维平面 ...
- 【洛谷 P1452】 Beauty Contest (二维凸包,旋转卡壳)
题目链接 旋转卡壳模板题把. 有时间再补总结吧. #include <cstdio> #include <cmath> #include <algorithm> u ...
- 洛谷P4645 [COCI2006-2007 Contest#7] BICIKLI [Tarjan,拓扑排序]
题目传送门 BICIKLI 题意翻译 给定一个有向图,n个点,m条边.请问,1号点到2号点有多少条路径?如果有无限多条,输出inf,如果有限,输出答案模10^9的余数. 两点之间可能有重边,需要看成是 ...
- P1452 Beauty Contest 旋转卡壳
\(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...
- P1452 Beauty Contest
传送门 求凸包周长,用旋转卡壳,具体可见yyb大佬的博客 顺便一提这题暴力+随机化也能过 暴力代码 //minamoto #include<bits/stdc++.h> #define r ...
- 洛谷P4891 序列 || 膜法阵,魔法阵
https://www.luogu.org/problemnew/show/P4891 一道几乎一样的题http://210.33.19.103/contest/1130/problem/3 题面ht ...
- Guard Duty (medium) Codeforces - 958E2 || (bzoj 2151||洛谷P1792) 种树 || 编译优化
https://codeforces.com/contest/958/problem/E2 首先求出N个时刻的N-1个间隔长度,问题就相当于在这些间隔中选K个数,相邻两个不能同时选,要求和最小 方法1 ...
- BZOJ 1901 洛谷 P2617 ZOJ 2112 Dynamic Rankings
以下时空限制来自zoj Time limit 10000 ms Memory limit 32768 kB OS Linux Source Online Contest of Christopher' ...
随机推荐
- 2019年猪年海报PSD模板-第八部分
11套精美猪年海报,免费猪年海报,下载地址:百度网盘,https://pan.baidu.com/s/1Y3wc_r7O-Dp0mLCihJ9mtQ
- Linux命令应用大词典-第8章 日期和时间
8.1 cal:显示日历信息 8.2 date:显示和设置系统日期和时间 8.3 hwclock:查看和设置硬件时钟 8.4 clock:查看和设置硬件时钟 8.5 clockdiff:主机之间测量时 ...
- Python安装教程最新版
Python安装教程最新版 目前Python官网已经更新到了最新版Python 3.7.1, 相比Python 2系列,它的兼容性不是太好, 不过应该会在不久的将来会全面解决.它的安装比较容易,具体步 ...
- lesson 18 Electric currents in modern art
lesson18 Electric currents in modern art electricity n. 电力:电流; electric adj. 电的:电动的; electronic adj. ...
- MySQL三方面优化
第一方面:30种mysql优化sql语句查询的方法1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中使用 ...
- Python版本切换和Pip安装
Python版本切换 现在常用的linux系统中都会默认携带python运行环境,在ubuntu 16.04 和centos 7.3中携带有Python 2.7 和Python3.5两个版本, 默认使 ...
- 【第二章】Shell 变量
一.什么是变量? 变量就是一个固定的字符串(也可以是字符.数字的组合)代替更多.更复杂的内容,该内容可能是变量.路径.字符串等其他内容. 变量就是程序中保存用户数据的一块内存空间,而变量名就是这块内存 ...
- Python3 Tkinter-Radionbutton
1.创建单选按钮 from tkinter import * root=Tk() Radiobutton(root,text='b1').pack() Radiobutton(root,text='b ...
- 五:ResourceManager High Availability RM 高可用
RM有单点失败的风险,但是可以做HA. RMs HA通过master/standby这种结构实现,一个master是active的,其它standby是inactive的.可能通过命令行切换主备节点 ...
- 学霸系统ui部分软件发布说明
一.版本新功能 1.搜索主页按钮 在学长的版本中,要想进入搜索主页,方法只有一个,就是在问答搜索结果页中点击链接进入搜索主页,这就使得用户很不方便.我们在学霸系统的主页增加了一个链接按钮,方便用户能够 ...