传送门

旋转卡壳板子题。

就是求凸包上最远点对。


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

注意要时刻更新最大值。

代码:

#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. C# EF 基础操作

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. C# ADO.NET 封装的增删改查

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  3. leetcode944

    public class Solution { public int MinDeletionSize(string[] A) { ; ; j < A[].Length; j++) { ; i & ...

  4. 用yield 实现协程 (包子模型)

    协程是一种轻量级的线程 无需线程上下级的开销, 所有的协程都在一个线程内执行 import time def consumer(name): print('%s is start to eat bao ...

  5. Error 2503 and 2502 when installing/uninstalling on Windows 10

    1. Hold Ctrl+Shift and press Esc. 2. Locate “Windows Explorer” under “Windows processes”, now right ...

  6. EditorGUILayout,GUILayout

    bool active=EditorGUILayout.Toggle("active",_bodyObj.active);//bool类型 b2BodyType type=(b2B ...

  7. 【342】Linear Regression by Python

    Reference: 用scikit-learn和pandas学习线性回归 首先获取数据存储在 pandas.DataFrame 中,获取途径(CSV 文件.Numpy 创建) 将数据分成 X 和 y ...

  8. XML文件的写,集合XML序列化(写)。XML文件的读,递归遍历

    XML文件:必须要有一个节点.检验xml文件,可以用浏览器打开,能打开表示对,否则错. 处理方法: DOM:XmlDocument文档对象模型 Sax(事件驱动,XmlReader) XmlSeria ...

  9. mesos无执行器启动docker

    生成taskInfo task = mesos_pb2.TaskInfo() task_id = name task.task_id.value = task_id task.slave_id.val ...

  10. sql重复数据只取一条记录

    1.SQL SELECT DISTINCT 语句 在表中,可能会包含重复值.这并不成问题,不过,仅仅列出不同(distinct)的值. 关键词 DISTINCT 用于返回唯一不同的值. 语法: SEL ...