传送门

旋转卡壳板子题。

就是求凸包上最远点对。


直接上双指针维护旋转卡壳就行了。

注意要时刻更新最大值。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 50005
using namespace std;
inline int read(){
	int ans=0,w=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans*w;
}
int n,q[N],top=0;
int ans=0.0;
struct pot{
	int x,y;
	inline pot operator-(const pot&a){return (pot){x-a.x,y-a.y};}
	inline int operator^(const pot&a){return x*a.y-y*a.x;}
	inline int dist(){return x*x+y*y;}
}p[N];
inline bool cmp(pot a,pot b){
	int ret=(a-p[1])^(b-p[1]);
	if(ret!=0)return ret>=0;
	return a.dist()<b.dist();
}
inline void graham(){
	int tmp=1;
	for(int i=2;i<=n;++i)if(p[i].x<p[tmp].x||(p[i].x==p[tmp].x&&p[i].y<p[tmp].y))tmp=i;
	if(tmp^1)swap(p[tmp],p[1]);
	sort(p+2,p+n+1,cmp),q[++top]=1;
	for(int i=2;i<=n;++i){
		while(top>=2&&((p[i]-p[q[top-1]])^(p[q[top]]-p[q[top-1]]))>=0)--top;
		q[++top]=i;
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;++i)p[i].x=read(),p[i].y=read();
	graham();
	if(top==2)return cout<<(p[q[top]]-p[q[top-1]]).dist(),0;
	q[++top]=1;
	for(int i=1,j=3;i<=top;++i){
		while(i%top+1!=j&&((p[q[i+1]]-p[q[i]])^(p[q[j]]-p[q[i]]))<=((p[q[i+1]]-p[q[i]])^(p[q[j+1]]-p[q[i]])))j=j%top+1;
		ans=max(ans,(p[q[j]]-p[q[i]]).dist()),ans=max(ans,(p[q[j]]-p[q[i+1]]).dist());
	}
	cout<<ans;
	return 0;
}

2018.10.18 poj2187Beauty Contest(旋转卡壳)的更多相关文章

  1. POJ2187Beauty Contest 旋转卡壳

    题目链接 http://poj.org/problem?id=2187 先求凸包 再求凸多边形直径 旋转卡壳模板题 #include<cstdio> #include<cstring ...

  2. 2018.10.18 bzoj1185: [HNOI2007]最小矩形覆盖(旋转卡壳)

    传送门 不难看出最后的矩形一定有一条边与凸包某条边重合. 因此先求出凸包,然后旋转卡壳求出当前最小矩形面积更新答案. 代码: #include<bits/stdc++.h> #define ...

  3. poj2187 Beauty Contest(旋转卡壳)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Beauty Contest Time Limit: 3000MS   Memor ...

  4. poj 2187:Beauty Contest(旋转卡壳)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32708   Accepted: 10156 Description Bes ...

  5. P1452 Beauty Contest 旋转卡壳

    \(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...

  6. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  7. poj 2187 Beauty Contest——旋转卡壳

    题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  8. hard(2018.10.18)

    题意:给你一棵\(n\)个节点的树,\(q\)个询问,每次询问读入\(u,v,k,op\),需要满足树上有\(k\)对点的简单路径交都等于\(u,v\)之间的简单路径,\(op=1\)表示\(k\)对 ...

  9. cdq(2018.10.18)

    一句话题意:给你三个数列{a_i},{b_i},{c_i},保证每个数列都恰好是一个排列.你需要求出满足\(a_i<a_j,b_i<b_j,c_i<c_j\)的有序对\((i,j)\ ...

随机推荐

  1. Maven的几个常用plugin

    出自:https://www.cnblogs.com/zhangxh20/p/6298062.html maven-compiler-plugin 编译Java源码,一般只需设置编译的jdk版本 &l ...

  2. git创建仓库,并提交代码(第一次创建并提交)(转)

    一直想学GIT,一直不曾学会.主要是GUI界面的很少,命令行大多记不住.今天尝试提交代码,按GIT上给的方法,没料到既然提交成功了. 于是把它记下来,方便以后学习. 代码是学习用的,没多大意义: 下图 ...

  3. JAVA WEB开发中的会话跟踪

    常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端记录信息确定用户身份. Http协议是一种无状态的协议,一旦数据交换完毕,客 ...

  4. CDLinux制作成U盘启动

    由于CDLinux在虚拟机跑的时候无法识别集成的笔记本网卡,故在此进行一下相关步骤的整理. 工具: U盘 UNetbootin 步骤: 1.插入U盘到电脑.不一定要在操作之前进行格式化,我目前的U盘分 ...

  5. Haskell语言学习笔记(34)System.Environment

    System.Environment getArgs :: IO [String] getProgName :: IO String getExecutablePath :: IO FilePath ...

  6. java编写一个汽车类,有属性:品牌、型号、排量、速度,有方法:启动、加速、转弯、刹车、息火

    /* * 汽车实体类 * 类里面有属性和方法 */public class Car {    String  brand;   //汽车品牌    String modelNumber; //汽车型号 ...

  7. js正则表达使用实例

    (1)替换掉htmlStr中所有的<font..>和</font> var htmlstr='<font color="#fff">ABC< ...

  8. chrome 调试跨域iframe

    相关链接:https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome https://stacko ...

  9. ASP.NET中UrlEncode应该用Uri.EscapeDataString()(转)

    今天,茄子_2008反馈他博客中的“C++”标签失效.检查了一下代码,生成链接时用的是HttpUtility.UrlEncode(url),从链接地址获取标签时用的是HttpUtility.UrlDe ...

  10. 如何用INNO安装添加快捷启动方式到Win7的快速启动栏(超级任务栏)

    问题:如何用INNO安装添加快捷启动方式到Win7的快速启动栏(超级任务栏) 在XP下,添加方式是直接把快捷方式复制到%appdata%\Microsoft\Internet Explorer\Qui ...