poj 2187
求凸包后枚举凸包上的点
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 100010
#define INF 0x7fffffff
#define inf 100000000
#define MOD 1000000007
#define ULL unsigned long long
#define LL long long using namespace std; const double ESP = 1e-10; double add(double a, double b) {
if(abs(a+b) < ESP * (abs(a) + abs(b))) return 0;
return a+b;
} struct P
{
double x, y; P() {} P(double x, double y) : x(x), y(y) {} P operator - (P p) {
return P(add(x, -p.x), add(y, -p.y));
} P operator + (P p) {
return P(add(x, p.x), add(y, p.y));
} P operator * (double d) {
return P(x*d, y*d);
} double dot(P p) {
return add(x*p.x, y*p.y);
} double det(P p) {
return add(x*p.y, - y*p.x);
}
}; P ps[maxn];
int n; bool cmp_x(const P& p, const P& q) {
if(p.x != q.x) return p.x < q.x;
return p.y < q.y;
} vector<P> convex_full() {
sort(ps, ps+n, cmp_x);
int k = 0;
vector<P> qs(n*2);
for(int i = 0; i < n; ++ i) {
while(k > 1 && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0)
-- k;
qs[k++] = ps[i];
} for(int i = n-2, t = k; i >= 0; -- i) {
while(k > t && (qs[k-1] - qs[k-2]).det(ps[i] - qs[k-1]) <= 0)
-- k;
qs[k++] = ps[i];
}
qs.resize(k-1);
return qs;
} double dist(P p, P q) {
return (p-q).dot(p-q);
} void solve() {
vector<P> qs = convex_full();
// printf("%d\n", qs.size());
double res = 0;
for(int i = 0; i < (int)qs.size(); ++ i) {
for(int j = 0; j < i; ++ j) {
res = max(res, dist(qs[i], qs[j]));
}
}
printf("%.0lf\n", res);
} int main()
{
while(scanf("%d", &n) == 1) {
for(int i = 0; i < n; ++ i) {
scanf("%lf%lf", &ps[i].x, &ps[i].y);
}
solve();
}
return 0;
}
poj 2187的更多相关文章
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- Poj 2187 旋转卡壳
Poj 2187 旋转卡壳求解 传送门 旋转卡壳,是利用凸包性质来求解凸包最长点对的线性算法,我们逐渐改变每一次方向,然后枚举出这个方向上的踵点对(最远点对),类似于用游标卡尺卡着凸包旋转一周,答案就 ...
- Poj 2187 凸包模板求解
Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- poj 2187 凸包加旋转卡壳算法
题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...
- ●POJ 2187 Beauty Contest
题链: http://poj.org/problem?id=2187 题解: 计算几何,凸包,旋转卡壳 一个求凸包直径的裸题,旋转卡壳入门用的. 代码: #include<cmath> # ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ - 2187 Beauty Contest(最远点对)
http://poj.org/problem?id=2187 题意 给n个坐标,求最远点对的距离平方值. 分析 模板题,旋转卡壳求求两点间距离平方的最大值. #include<iostream& ...
- poj 2187 Beauty Contest——旋转卡壳
题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
随机推荐
- pure的bug记录2
<select id="stacked-state" style=" font-family: "Microsoft YaHei"; " ...
- 几道华为经典C语言面试题
1.找错 void test1() { char string[10]; char* str1="0123456789"; strcpy(string, str1); } 这里st ...
- IE10-浏览器实现placeholder效果
如下图,在文本框为空时显示提示文字 在IE10+和chrome浏览器加placeholder属性及可实现 ,单在IE10-浏览器并不支持该属性, 以下是placeholder在IE10-浏览器的实现 ...
- apache 403错
<Directory />Options FollowSymLinksAllowOverride NoneOrder deny,allowAllow from all</Direct ...
- [转]Oracle_ProC编程
1.引言 由于PL/SQL不能用来开发面向普通用户的应用程序,必须借助其他语言或开发工具. 在Linux操作系统下应该用什么语言或开发工具来进行Oracle数据库应用的开发呢?本文将介绍2种方案:Pr ...
- oracle 归档/非归档
1.查看oralce是归档模式还是非归档模式 SQL> select name,log_mode from v$database; NAME LOG_MODE------------------ ...
- Android--Fragment的懒加载
我们都知道,fragment放在viewPager里面,viewpager会帮我们预先加载一个,但是当我们要看fragment里面的内容时,我们也许只会去看第一个,不会去看第二个,如果这时候不去实现f ...
- Windows PowerShell ISE
Windows PowerShell 集成脚本环境 (ISE) 是 Windows PowerShell 的主机应用程序.在 Windows PowerShell ISE 中,可以在单一 Window ...
- iOSReachability判断网络连接状态
// // NetStateManage.h // // Created by miniu on 15/11/24. // Copyright © 2015年 mini. All rights ...
- 转:CentOS 7 安装Nginx
一.准备工作: 1.安装必备工具: ? 1 2 3 $ yum -y install gcc gcc-c++ autoconf automake $ yum -y install zlib zli ...