Poj 2187 凸包模板求解
Poj 2187 凸包模板求解
传送门
由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define inf 1000000000LL
#define mod 1000000007
using namespace std;
int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
const int N = 5e4+10;
const double PI = acos(-1.0);
const double eps = 1e-12;
int dcmp(double x) {
if(fabs(x)<eps) return 0; else return x<0? -1:1;
}
struct Pt {
double x,y;
Pt(double x=0,double y=0) :x(x),y(y) {};
};
typedef Pt vec;
vec operator - (Pt a,Pt b) { return vec(a.x-b.x,a.y-b.y); }
vec operator + (vec a,vec b) { return vec(a.x+b.x,a.y+b.y); }
bool operator == (Pt a,Pt b) {
return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;
}
bool operator < (const Pt& a,const Pt& b) {
return a.x<b.x || (a.x==b.x && a.y<b.y);
}
vec rotate(vec a,double x) {
return vec(a.x*cos(x)-a.y*sin(x),a.x*sin(x)+a.y*cos(x));
}
double cross(vec a,vec b) { return a.x*b.y-a.y*b.x; }
double dist(Pt a,Pt b) {
//return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
return ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
vector<Pt> ConvexHull(vector<Pt> p) {
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
int n=p.size() , m=0;
vector<Pt> ch(n+1);
for(int i=0;i<n;i++) {
while(m>1 && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
int k=m;
for(int i=n-2;i>=0;i--) {
while(m>k && cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
ch[m++]=p[i];
}
if(n>1) m--;
ch.resize(m); return ch;
}
vector<Pt>q,con;
int main(){
int n=read();
int x,y;
for(int i=0;i<n;i++){
x=read();y=read();
q.push_back(Pt((double)x,(double)y));
}
con=ConvexHull(q);
double ans=0;
for(int i=0;i<con.size();i++){
for(int j=i+1;j<con.size();j++){
ans=max(ans,dist(con[i],con[j]));
}
}
printf("%.0f\n",ans);
return 0;
}
Poj 2187 凸包模板求解的更多相关文章
- poj 2187 凸包加旋转卡壳算法
题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...
- POJ 1113 凸包模板题
上模板. #include <cstdio> #include <cstring> #include <iostream> #include <algorit ...
- POJ 2187 凸包+旋转卡壳
思路: 求个凸包 旋转卡壳一下 就求出来最远点对了 注意共线情况 也就是说 凸包如果有一堆点共线保留端点即可 //By SiriusRen #include <cmath> #incl ...
- POJ 2187 /// 凸包入门 旋转卡壳
题目大意: 求最远点对距离 求凸包上的最远点对 挑战263页 #include <cstdio> #include <string.h> #include <algori ...
- Poj 2187 旋转卡壳
Poj 2187 旋转卡壳求解 传送门 旋转卡壳,是利用凸包性质来求解凸包最长点对的线性算法,我们逐渐改变每一次方向,然后枚举出这个方向上的踵点对(最远点对),类似于用游标卡尺卡着凸包旋转一周,答案就 ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- 简单几何(凸包) POJ 2187 Beauty Contest
题目传送门 题意:求两点的距离平方的最大值 分析:凸包模板题 /************************************************ * Author :Running_T ...
- poj 2187:Beauty Contest(计算几何,求凸包,最远点对)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26180 Accepted: 8081 D ...
随机推荐
- 利用爬虫将Yuan先生的博客文章爬取下来
由于一次巧遇,我阅读了Yuan先生的一篇博客文章,感觉从Yuan先生得博客学到很多东西,很喜欢他得文章.于是我就关注了他,并且想阅读更多出自他手笔得博客文章,无奈,可能Yuan先生不想公开自己得博客吧 ...
- 进击的Python【第十五章】:Web前端基础之DOM
进击的Python[第十五章]:Web前端基础之DOM 简介:文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它给文档提供了一种结构化的表示 ...
- 题解报告:NYOJ #311完全背包(恰好装满)
描述: 直接说题意,完全背包定义有N种物品和一个容量为V的背包,每种物品都有无限件可用.第i种物品的体积是c,价值是w.求解将哪些物品装入背包可使这些物品的体积总和不超过背包容量,且价值总和最大.本题 ...
- Drawable(7)让一个没有pressed状态的控件使用StateList,显示pressed图片。
TextView没有按下状态,Button有. 如图1,内容1在一个TextView上,默认它并没有按下状态. 如何让TextView有呢. 在xml中加入属性: android:clickable= ...
- 对数组随机赋值,并输出(Arrays.toString(arr))
import java.util.Arrays; public class Demo { public static void main(String[] args) { int[] arr = ne ...
- [转]linux之date命令MYSQL用户管理
转自:http://www.cnblogs.com/hencehong/archive/2013/03/19/mysql_user.html 一. 用户登录 格式: mysql -h主机 ...
- CF792C Divide by Three
思路: dp. 实现: #include <iostream> #include <cstdio> #include <cstring> #include < ...
- CSS综合用法
div 居中 {position: absolute; top: 50%; left: 50%; margin-top: -180px; margin-left: -160px;}
- LoadRunner 11中Record无法自动生成脚本——解决办法
[问题描述] 安装loadRunner 11, 使用IE为默认浏览器,打开一个页面进行脚本录制:录制完成后,无法生成脚本. [问题现象] 控制台输出如下: ****** Start Log Messa ...
- 掌握Spark机器学习库-05-spark中矩阵与向量的使用
1)介绍 矩阵: Matrix,看做二维表,基本运算(+,-,*,T) 向量: Vectors,方向和大小,基本运算,范数 2)spark中向量的使用(主要使用breeze.linalg) 3)spa ...