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 ...
随机推荐
- Unix\Linux | 总结笔记 | 用户管理
1. useradd [选项] 用户名 用于创建新的用户 useradd命令中的用户参数以及作用 参数 作用 -d 指定用户的家目录(默认为/home/username) -e 账户的到期时间,格 ...
- _bzoj1003 [ZJOI2006]物流运输【预处理】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1003 预处理出第i天到第j天走一条航线时的最短路. #include <cstdio& ...
- Latex新人教程
1.LaTeX软件的安装和使用 方法A(自助):在MikTeX的官网下载免费的MikTeX编译包并安装.下载WinEdt(收费)或TexMaker(免费)等编辑界面软件并安装. 方法B(打包):在ct ...
- AngularJS开发最常犯的10个错误
简介 AngularJS是目前最为活跃的Javascript框架之一,AngularJS的目标之一是简化开发过程,这使得AngularJS非常善于构建小型app原型,但AngularJS对于全功能的客 ...
- ASP.NET网站发布到服务器
我们一个项目做好了之后想要上线,首先得发布,然后在上传到服务器. 所用到的工具:vs2013(其它vs版本也可以,大致上是一样的) FTP破解版下载链接:http://files.cnblogs.co ...
- window.form增删改查
效果展示: 查询: 可以查询姓名:民族:姓名+民族:都是空的查询全部 取值取得是姓名: 删除: 修改: 先选中查询之后修改: 添加: 代码部分: 第一张表: 第二张表:主表,民族代码加名称 natio ...
- Android 更新方案实现
需求说明 为了保证自己 APP 的新版本使用率,现在有很多已有的“软件更新”框架供各位使用,本文的主要内容是如何自己动手来实现软件的后台下载,更新. 下面详细说明下软件更新的逻辑,流程图如下: 每步详 ...
- Map接口框架图
Java集合大致可分为Set.List和Map三种体系,其中Set代表无序.不可重复的集合:List代表有序.重复的集合:而Map则代表具有映射关系的集合.Java 5之后,增加了Queue体系集合, ...
- 总结几点sql语句优化
一.表设计阶段: 1.主键的使用 a.业务日志表.安全审计表采用自增长: b.自定义编号用于业务流程类表,根据一定的编号规则: c.int型主键 用于基础数据表: 2.逻辑删除字段的 ...
- Struts1 MVC框架的工作原理
MVC英文及Model-View-Controller,分别是模型(Model),视图(View)和控制(Controller).MVC模式的目的是实现web系统的职能分工. View:即用户交互界面 ...