http://poj.org/problem?id=2187

显然直径在凸包上(黑书上有证明)。(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴。。。。。没有排序y轴。。

然后本题数据水,暴力也能过。。。

(之前一直以为距离是单增的,其实并不是,应该是三角形面积单增...)

考虑旋转卡壳

一篇好的文章:http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html

首先对踵点就是两条平行线夹紧凸包的两个点(或者3个点或4个点,平行线过两个点情况,凸包去掉三点共线)时的点对,可以证明对踵点对最多只有3N/2个

首先卡住一点-两点(即边)可以等效于卡主一点-一点(前边的点),所以我们只需要找边的前一个点的对踵点即可。

性质1:对踵点对之间的距离最大

证明:黑书上有...

因此我们只需要枚举每条边,找出对应的对踵点(用叉积求面积来找,这条边与其它点的面积是单峰的,然后往后递推决策是单调不降的)

性质2:当枚举边按序枚举时,对踵点的位置单增

证明:不会QAQ似乎黑书上也有?

这就提供了一个很好的性质,即我们枚举边时维护一下对踵点的位置即可,那么查找对踵点的复杂度均摊$O(n)$

性质3:每个点的对踵点不一定只有1个

证明:显然吧。。。

由于性质3的存在,我们考虑是否我们枚举边找到第一个对踵点就更新的算法会出现问题?

答案是不会。

因为我们枚举边时已经遍历了所有点,因此遗漏的对踵点的距离总是会计算到

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mkpii make_pair<int, int>
#define pdi pair<double, int>
#define mkpdi make_pair<double, int>
#define pli pair<ll, int>
#define mkpli make_pair<ll, int>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=50005;
struct dat { int x, y; }a[N], b[N]; int cha(const dat &a, const dat &b, const dat &c) {
static int x1, x2, y1, y2;
x1=a.x-c.x, x2=b.x-c.x, y1=a.y-c.y, y2=b.y-c.y;
return x1*y2-x2*y1;
}
int n;
bool cmp(const dat &a, const dat &b) { return a.x==b.x?a.y<b.y:a.x<b.x; }
void tu() {
sort(a+1, a+1+n, cmp);
int top=0;
for1(i, 1, n) {
while(top>1 && cha(a[i], b[top], b[top-1])>=0) --top;
b[++top]=a[i];
}
int k=top;
for3(i, n-1, 1) {
while(top>k && cha(a[i], b[top], b[top-1])>=0) --top;
b[++top]=a[i];
}
if(n>1) --top;
n=top;
}
int sqr(const int x) { return x*x; }
int dis(const dat &a, const dat &b) { return sqr(a.x-b.x)+sqr(a.y-b.y); } int main() {
read(n);
for1(i, 1, n) read(a[i].x), read(a[i].y);
tu();
int ans=0;
b[n+1]=b[1];
int j=2;
for1(i, 1, n) {
while(cha(b[i+1], b[j+1], b[i])>cha(b[i+1], b[j], b[i])) j=j%n+1;
ans=max(ans, dis(b[i], b[j]));
}
printf("%d\n", ans);
return 0;
}

  


Description

Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the title 'Miss Cow World'. As a result, Bessie will make a tour of N (2 <= N <= 50,000) farms around the world in order to spread goodwill between farmers and their cows. For simplicity, the world will be represented as a two-dimensional plane, where each farm is located at a pair of integer coordinates (x,y), each having a value in the range -10,000 ... 10,000. No two farms share the same pair of coordinates.

Even though Bessie travels directly in a straight line between pairs of farms, the distance between some farms can be quite large, so she wants to bring a suitcase full of hay with her so she has enough food to eat on each leg of her journey. Since Bessie refills her suitcase at every farm she visits, she wants to determine the maximum possible distance she might need to travel so she knows the size of suitcase she must bring.Help Bessie by computing the maximum distance among all pairs of farms.

Input

* Line 1: A single integer, N

* Lines 2..N+1: Two space-separated integers x and y specifying coordinate of each farm

Output

* Line 1: A single integer that is the squared distance between the pair of farms that are farthest apart from each other. 

Sample Input

4
0 0
0 1
1 1
1 0

Sample Output

2

Hint

Farm 1 (0, 0) and farm 3 (1, 1) have the longest distance (square root of 2) 

Source

【POJ】2187 Beauty Contest(旋转卡壳)的更多相关文章

  1. poj 2187:Beauty Contest(旋转卡壳)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32708   Accepted: 10156 Description Bes ...

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

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

  3. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

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

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

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

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

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

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

  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 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  9. POJ 2187 Beauty Contest(凸包,旋转卡壳)

    题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...

  10. POJ 2187 Beauty Contest(凸包+旋转卡壳)

    Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...

随机推荐

  1. TCP中 recv和sendf函数

    recv和send函数: #include<sys/socket.h> ssize_t recv(int sockfd, void *buff, size_t nbytes, int fl ...

  2. C++复数四则运算的实现

    程序主要实现复数的加减乘,数乘,取共轭功能. 将所有函数都定义为了成员函数. 使用库函数atof将字符串转换为浮点型数据. 函数主要难点在于处理输入.由于需要判断输入是选择退出还是继续,所以用字符串来 ...

  3. Hadoop入门程序WordCount的执行过程

    首先编写WordCount.java源文件,分别通过map和reduce方法统计文本中每个单词出现的次数,然后按照字母的顺序排列输出, Map过程首先是多个map并行提取多个句子里面的单词然后分别列出 ...

  4. Java for LeetCode 025 Reverse Nodes in k-Group

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...

  5. 【JAVA、C++】LeetCode 016 3Sum Closest

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  6. 【python】zip()函数

    来源:http://www.cnblogs.com/frydsh/archive/2012/07/10/2585370.html zip函数接受任意多个(包括0个和1个)序列作为参数,返回一个tupl ...

  7. Linux 中文乱码问题

    弄了好久还是乱码 最终方法:进入 vim /etc/vimrc中 原先只有一个 set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936改成: let ...

  8. asp.net mvc int[] 和 string[] 自定义数组绑定

    新建类,int[]数组模型绑定 using System; using System.Collections.Generic; using System.Linq; using System.Web; ...

  9. **对比$_POST、$GLOBALS['HTTP_RAW_POST_DATA']和file_get_contents('php://input')

    最近在开发微信接口,又学到了一些新的技术点,今天就把学到的关于接收数据的技术点给简单的罗列下. public function __construct($token, $wxuser = ''){ $ ...

  10. win + linux + android 多任务分屏

    Win10 的多任务分屏操作方法_百度经验http://jingyan.baidu.com/article/48206aeaf6ef35216ad6b336.html win+方向键 如果是想四分屏幕 ...