求凸包后枚举凸包上的点

#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的更多相关文章

  1. poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)

    /* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...

  2. Poj 2187 旋转卡壳

    Poj 2187 旋转卡壳求解 传送门 旋转卡壳,是利用凸包性质来求解凸包最长点对的线性算法,我们逐渐改变每一次方向,然后枚举出这个方向上的踵点对(最远点对),类似于用游标卡尺卡着凸包旋转一周,答案就 ...

  3. Poj 2187 凸包模板求解

    Poj 2187 凸包模板求解 传送门 由于整个点数是50000,而求凸包后的点也不会很多,因此直接套凸包之后两重循环即可求解 #include <queue> #include < ...

  4. poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)

    链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...

  5. poj 2187 凸包加旋转卡壳算法

    题目链接:http://poj.org/problem?id=2187 旋转卡壳算法:http://www.cppblog.com/staryjy/archive/2009/11/19/101412. ...

  6. ●POJ 2187 Beauty Contest

    题链: http://poj.org/problem?id=2187 题解: 计算几何,凸包,旋转卡壳 一个求凸包直径的裸题,旋转卡壳入门用的. 代码: #include<cmath> # ...

  7. POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]

    题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...

  8. POJ - 2187 Beauty Contest(最远点对)

    http://poj.org/problem?id=2187 题意 给n个坐标,求最远点对的距离平方值. 分析 模板题,旋转卡壳求求两点间距离平方的最大值. #include<iostream& ...

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

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

  10. POJ 2187 Beauty Contest【旋转卡壳求凸包直径】

    链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

随机推荐

  1. C#读取和写入配置文件

    使用.Net2.0中的ConfigurationManager可以方便的实现对配置app.config的读取和写入. ConfigurationManager默认没有自动载入项目,使用前必须手动添加, ...

  2. 第八节 C#的using语句

    前面的代示例展示了如果调用一个类型的Dispose或Close方法.如果决定显式的调用这两个方法之一,强烈建议吧他们放在一个异常处理finally块中.这样可以保证清理代码得到执行,因此,前代码示例可 ...

  3. python爬取糗百第一页的笑话

    自学python网络爬虫,发现request比urllib还是要好用一些,因此利用request和BeautifulSoup来实现糗百的首页笑话的抓取.BeautifulSoup通过find和find ...

  4. R语言的字符串处理

    R语言字符串的拼接 content<-paste("124235","789","124",sep="@") 运行 ...

  5. Power of Four

    Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...

  6. 批处理判断是否存在文件,存在则运行另外一个bat文件

    现在需求如下: 使用bat文件判断是否存在ktr文件,存在则运行pan.bat,执行kettle脚本. 代码如下: @echo off @title 批处理判断文件夹是否存在 cd /d F: rem ...

  7. 在VS2010 SP1基础上安装mvc3

    安装VS2010 SP1后,再安装mvc3会报错,估计原因是此安装包会安装VS的补丁,而sp1的补丁版本高过此安装包的. AspNetMVC3ToolsUpdateSetup.exe 解决办法: 运行 ...

  8. 部署ghost博客

    wget https://ghost.org/zip/ghost-0.6.4.zip npm install --production NODE_ENV=production npm start &g ...

  9. meteor icons & splash配置

    ionic resources http://ionicframework.com/docs/cli/icon-splashscreen.html 用一条指令生成ionic生需Icons & ...

  10. R语言连接MYSQL

    操作系统:centos 6.4 64bit R语言可以使用RMySQL来连接Mysql数据库,直接使用数据库里面的数据生成图像. 这个是RMYSQL的说明: http://cran.r-project ...