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 ...
随机推荐
- JAVA里的字符串,String 类简单介绍
http://www.360doc.com/content/14/1107/23/17130779_423471141.shtml
- 实战Django:简易博客Part1
舍得学习新技能的时候,通常不喜欢傻读书--捧着一本阐述该项技能的书籍,然后傻看,一路看下来,脑子里塞满了新的概念.知识点,头是越来越大,但技能却几乎没掌握半分. 多年来,舍得养成了用做实例来学习新技能 ...
- xdebug
必须的有4个(remote_enable 默认没开,所以必要),其它默认值一般可以xdebug.remote_enable=On; //这个是必须xdebug.remote_host=192.168. ...
- 禁止生成文件Thumbs.db
Thumbs.db是一个用于Microsoft Windows XP.Windows7 或 mac os x缓存Windows Explorer的缩略图的文件.Thumbs.db保存在每一个包含图片或 ...
- shell-IF判断
#!/bin/bash echo "-----------------strat---------------" read -p "Enter a number:&quo ...
- Ubuntu14.04 Objective-C hello world
1. Install GNUstep sudo apt-get install gnustep gnustep-devel 2. Write hello world program, and save ...
- iOS学习之C语言分支结构
一.BOOL类型 返回值:真:YES 假:NO 定义一个布尔类型的变量 YES == 1, NO == 0 计算机在识别时,YES就替换成1,NO就替换成0 BOOL isGirl = YES; ...
- 关于DataSource的一些记录
今天看WWDC的232_hd_advanced_user_interfaces_with_collection_views,里面花了一般的时间来讲如何合理的设计程序的datesource,将的很有道理 ...
- 调整maven配置文件
maven的配置文件位置:maven安装位置\conf\settings.xml. 这次调整maven的配置文件主要解决三个问题: 调整本地依赖库位置 设置代理 添加远程资源库镜像节点 调整本地依赖库 ...
- java数据结构和算法------堆排序
package iYou.neugle.sort; public class Heap_sort { public static void HeapSort(double[] array) { for ...