nyoj 253:LK的旅行 【旋转卡壳入门】
求平面最大点对。
找凸包 -> 根据凸包运用旋转卡壳算法求最大点对(套用kuang巨模板)
- #include<bits/stdc++.h>
- using namespace std;
- struct point
- {
- int x,y;
- point operator -(const point& rhs)const
- {
- point ret;
- ret.x=x-rhs.x;
- ret.y=y-rhs.y;
- return ret;
- }
- int operator *(const point& rhs)const//叉乘
- {
- return x*rhs.y-y*rhs.x;
- }
- bool operator <(const point& rhs)const
- {
- return x<rhs.x||x==rhs.x&&y<rhs.y;
- }
- } p[],s[];
- int top;
- bool ok(point A,point B,point C) //判断ABC是否是按逆时针顺序给出
- {
- ;
- }
- int dist2(point a,point b)
- {
- return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
- }
- int rotating_calipers()
- {
- ;
- point v;
- ;
- ; i < top; i++)
- {
- v = s[i]-s[(i+)%top];
- )%top]-s[cur])) < )
- cur = (cur+)%top;
- ret = max(ret,max(dist2(s[i],s[cur]),dist2(s[(i+)%top],s[(cur+)%top])));
- }
- return ret;
- }
- int main()
- {
- int T;
- scanf("%d",&T);
- while(T--)
- {
- int n;
- scanf("%d",&n);
- ; i<n; i++)
- scanf("%d%d",&p[i].x,&p[i].y);
- sort(p,p+n);
- top=;
- ; i<n; i++) //求下凸包
- {
- && !ok(s[top-],s[top-],p[i]))
- top--;
- s[top++]=p[i];
- }
- ;
- ; i>=; i--) //求上凸包
- {
- && !ok(s[top-],s[top-],p[i]))
- top--;
- s[top++]=p[i];
- }
- --top; // 首尾点相同,故舍去
- int ans=rotating_calipers();
- printf("%d\n",ans);
- }
- }
nyoj 253:LK的旅行 【旋转卡壳入门】的更多相关文章
- nyoj_253:LK的旅行(旋转卡壳入门)
题目链接 求平面最大点对. 找凸包 -> 根据凸包运用旋转卡壳算法求最大点对(套用kuang巨模板) 关于旋转卡壳算法 #include<bits/stdc++.h> using n ...
- nyoj-253-LK的旅行(Graham算法和旋转卡壳)
题目链接 /* Name:nyoj-253-LK的旅行 Copyright: Author: Date: 2018/4/27 15:01:36 Description: zyj的模板 */ #incl ...
- P1452 Beauty Contest 旋转卡壳
\(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...
- P1452 Beauty Contes(旋转卡壳版)
题目背景 此处省略1W字^ ^ 题目描述 贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”.因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意.世界将被表示成一个二维平面 ...
- 1393: Robert Hood 旋转卡壳 凸包
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1393 http://poj.org/problem?id=2187 Beauty Contest ...
- POJ 3608 Bridge Across Islands --凸包间距离,旋转卡壳
题意: 给你两个凸包,求其最短距离. 解法: POJ 我真的是弄不懂了,也不说一声点就是按顺时针给出的,不用调整点顺序. 还是说数据水了,没出乱给点或给逆时针点的数据呢..我直接默认顺时针给的点居然A ...
- 【BZOJ 1069】【SCOI 2007】最大土地面积 凸包+旋转卡壳
因为凸壳上对踵点的单调性所以旋转卡壳线性绕一圈就可以啦啦啦--- 先求凸包,然后旋转卡壳记录$sum1$和$sum2$,最后统计答案就可以了 #include<cmath> #includ ...
- 【POJ 2187】Beauty Contest(凸包直径、旋转卡壳)
给定点集的最远两点的距离. 先用graham求凸包.旋(xuán)转(zhuàn)卡(qiǎ)壳(ké)求凸包直径. ps:旋转卡壳算法的典型运用 http://blog.csdn.net/hanch ...
- 【BZOJ-1069】最大土地面积 计算几何 + 凸包 + 旋转卡壳
1069: [SCOI2007]最大土地面积 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2707 Solved: 1053[Submit][Sta ...
随机推荐
- 002-序列化装换JSON&XML概述
一.概述 https://github.com/bjlhx15/java-serializer java-serializer 序列化项目 serialize-json-lib:json-lib框架 ...
- Failed to load resource: the server responsed with a status of 400 (Bad Request)
浏览器报错:Failed to load resource: the server responsed with a status of 400 (Bad Request) ajax请求失败,一般情况 ...
- DELPHI之全局变量和局部变量
http://www.cnblogs.com/Stwo/archive/2011/07/11/2102816.html DELPHI之全局变量和局部变量 全局变量: 如果我们在应用程序一个单元中的in ...
- Vagrant 手册之 Vagrantfile - 机器设置 config.vm
原文地址 配置的命名空间:config.vm config.vm 中的设置修改 Vagrant 管理的机器的配置. 1. 可用的设置项 config.vm.boot_timeout Vagrant 等 ...
- hdu2602Bone Collector ——动态规划(0/1背包问题)
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- 类型(type)判断
windows下源文件编码问题 在windows下不要直接右击桌面创建.txt再改成.c,这种方式容易引起编码问题 windows下gvim的设置: 先打开gvim再用:w newfile.c这种方式 ...
- TCGA癌症缩写、癌症中英文对照
Cohort 英文名称 中文名称 ACC Adrenocortical carcinoma 肾上腺皮质癌 BLCA Bladder Urothelial Carcinoma 膀胱尿路上皮癌 BRCA ...
- 常用的AJAX弹出层代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- [BZOJ3626] [LNOI2014]LCA(树链剖分)
[BZOJ3626] [LNOI2014]LCA(树链剖分) 题面 给出一棵N个点的树,要求支持Q次询问,每次询问一个点z与编号为区间[l,r]内的点分别求最近公共祖先得到的最近公共祖先深度和.N, ...
- P4390 [BOI2007]Mokia 摩基亚
传送门 对于一个询问 $(xa,ya),(xb,yb)$,拆成 $4$ 个询问并容斥一下 具体就是把询问变成求小于等于 $xb,yb$ 的点数,减去小于等于 $xa-1,yb$ 和小于等于 $xb,y ...