【洛谷 P1452】 Beauty Contest (二维凸包,旋转卡壳)
2024-08-26 14:22:59
题目链接
旋转卡壳模板题把。
有时间再补总结吧。
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 100010;
struct point{
int x, y;
}p[MAXN];
int operator * (point a, point b){ // a x b
return a.x * b.y - b.x * a.y;
}
point operator - (point a, point b){
return (point){ a.x - b.x, a.y - b.y };
}
int cmp1(const point a, const point b){
return a.x == b.x ? a.y < b.y : a.x < b.x;
}
inline double k(point a, point b){
return a.x == b.x ? 1e18 : ((double)b.y - a.y) / (b.x - a.x);
}
inline double dis(point a, point b){
int px = b.x - a.x, py = b.y - a.y;
return sqrt(px * px + py * py);
}
inline int dp(point a, point b){
int px = b.x - a.x, py = b.y - a.y;
return px * px + py * py;
}
int n, top, tp, ans;
point st[MAXN], ts[MAXN];
inline double mult(point a, point b, point c){
return (a - c) * (b - c);
}
int SpecialJudge(){
for(int i = 2; i <= n; ++i)
if(p[i].y != p[i - 1].y)
return 0;
return 1;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d%d", &p[i].x, &p[i].y);
if(SpecialJudge()){
int Min = 0x3f3f3f3f, Max = -0x3f3f3f3f;
for(int i = 1; i <= n; ++i){
Min = min(Min, p[i].x);
Max = max(Max, p[i].x);
}
printf("%d\n", (Max - Min) * (Max - Min));
return 0;
}
sort(p + 1, p + n + 1, cmp1);
for(int i = 1; i <= n; ++i){
while(top > 1 && k(st[top - 1], p[i]) < k(st[top - 1], st[top])) --top;
st[++top] = p[i];
}
for(int i = 1; i <= n; ++i){
while(tp > 1 && k(ts[tp - 1], p[i]) > k(ts[tp - 1], ts[tp])) --tp;
ts[++tp] = p[i];
}
for(int i = tp - 1; i; --i) st[++top] = ts[i];
int j = 2;
for(int i = 1; i <= top; ++i){
while(mult(st[i], st[i + 1], st[j]) < mult(st[i], st[i + 1], st[j + 1]))
if(++j > top) j = 1;
ans = max(ans, max(dp(st[i], st[j]), dp(st[i + 1], st[j])));
}
printf("%d\n", ans);
return 0;
}
最新文章
- A页面调到B页面,B页面关闭时A页面刷新
- sqlserver text/ntext 字段读取
- 【leetcode】Climbing Stairs
- 封装获取dom元素
- 学霸网站---Alpha+版本测试报告
- 51nod 1007 正整数分组
- MongoDB与.NET结合使用二(安全)
- 13、C#基础整理(枚举)
- 图像特征提取三大法宝:HOG特征,LBP特征,Haar特征(转载)
- 使用Groovy构建自己的脚本环境
- VIMTUTOR《VIM教程》
- C#调用WebService实例和开发
- jquery Ztree v3.5 实例2 自定义显示在节点前的图片
- Apache 隐藏入口文件以及防盗链.htaccess 文件
- 如何通过 HSB 颜色模式构建夜间模式
- 关于hibernate的缓存使用(转)
- 面试陷阱1:Integer类型的比较
- #VSTS日志# Xamarin构建支持和一大波更新
- zookeeper 配置文件conf目录下 zoo文件 配置详解
- echo与print,var_dump()和print_r()的区别
热门文章
- DOS工具
- oracle 删除数据恢复
- java.awt.AWTError: Can&#39;t connect to X11 window server using &#39;:20&#39; as the value of the DISPLAY variable
- 【Python】ORM框架SQLAlchemy的使用
- hdu2295-Radar
- Atom Editor 插件 atom-less 的使用方法
- Python_css选择器
- [COGS2652]秘术「天文密葬法」
- BZOJ1061:[NOI2008]志愿者招募——题解
- 洛谷4525 &; 4526:【模板】自适应辛普森法——题解