Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 27218   Accepted: 8410

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)

题意如Hint。。这道题我是用凸包加枚举做的。。这竟然还是235ms....Orz。

。。

看别人是用旋转卡壳做的。。。

也就找了些资料看看。。。。

凸包+枚举:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath> using namespace std; #define f1(i, n) for(int i=0; i<n; i++)
#define f2(i, m) for(int i=1; i<=m; i++)
#define f3(i, n) for(int i=n; i>=0; i--)
#define f4(i, n) for(int i=2; i<=n; i++)
#define M 50050
double ans; struct Point
{
double x, y;
}; bool cmp (Point a1, Point a2)
{
return ((a1.x > a2.x) || (a1.x==a2.x && a1.y>a2.y) ); } int cross(int x1, int y1, int x2, int y2)
{
if(x1*y2-x2*y1<=0)
return 0;
else
return 1;
} double dis(Point a, Point b)
{
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
} int convexhull(Point *p, Point *c, int n)
{
int m = 0;
f1(i, n)
{
while( m>1 && !cross(c[m-2].x-c[m-1].x, c[m-2].y-c[m-1].y, c[m-2].x-p[i].x, c[m-2].y-p[i].y) )
m--;
c[m++] = p[i];
}
int k = m;
f3(i, n-2)
{
while( m>k && !cross(c[m-2].x-c[m-1].x, c[m-2].y-c[m-1].y, c[m-2].x-p[i].x, c[m-2].y-p[i].y) )
m--;
c[m++] = p[i];
}
if(n>1)
m--;
return m;
} int main()
{
Point a[M], p[M];
double sum;
int n, r;
while( cin>>n)
{
ans = -1.0;
f1(i, n)
scanf("%lf %lf", &a[i].x, &a[i].y);
if(n==2)
printf("%.lf\n", dis( a[1], a[0] ));
else
{
sort (a, a+n, cmp);
int m = convexhull(a, p, n);
f4(i, m) //枚举全部的两点距离。。
f2(j, m)
ans = max(ans, dis( p[i], p[j] ) );
printf("%.lf\n", ans);
} }
return 0;
}

由于我凸包用的不是扫描法。

Orz。。。

所以。

。还是在研究研究。。。

旋转卡壳的方法以及学习资料:

传送门:

点击打开链接

感谢这位博主。。资料弄的非常好。。

版权声明:本文博主原创文章。博客,未经同意不得转载。

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 —— 旋转卡壳

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

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

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

  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. 【C语言探索之旅】 第一部分第五课:运算那点事

    内容简介 1.课程大纲 2.第一部分第五课:运算那点事 3.第一部分第六课预告:条件表达式 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语言编写三个游戏 ...

  2. Objective-C开发编码规范

    Objective-C 编码规范,内容来自苹果.谷歌的文档翻译,自己的编码经验和对其它资料的总结. 概要 Objective-C 是一门面向对象的动态编程语言,主要用于编写 iOS 和 Mac 应用程 ...

  3. RH133读书 笔记(4) - Lab 4 System Services

    Lab 4 System Services Goal: Develop skills using system administration tools and setting up and admi ...

  4. bat(批处理文件)初步 第一篇 基本符号

    近期我使用的一款软件中须要大量的环境变量设置,而我又不想讲这些变量都加入到系统的环境变量中,一方面是由于有一些同名的库文件的版本号却不一样,都 写在系统环境中会相互干扰:还有一方面则是大部分的路径仅仅 ...

  5. HTTP响应代码

    HTTP响应代码 1xx - 消息通知 这些状态代码表示临时响应.client在收到常规响应.应准备接收一个或多个 1xx 应. · 100 - Continue 初始的请求已经接受,客户应当继续发送 ...

  6. RH133读书笔记(10)-Lab 10 Exploring Virtualization

    Lab 10 Exploring Virtualization Goal: To explore the Xen virtualization environment and the creation ...

  7. dba_dependencies查询结果视图

    [oracle@rhel63single ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 13 0 ...

  8. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

  9. Java多线程中wait, notify and notifyAll的使用

    本文为翻译文章,原文地址:http://www.journaldev.com/1037/java-thread-wait-notify-and-notifyall-example 在Java的Obje ...

  10. bzoj 2109 &amp; 2535 空中管制 解读

    [] [分析]小猪真的是一个很好的问题.我认为这是一个问题洪水.建立拓扑后(便! ).直接把最外层设定序号为1,第二层为2.bfs下去就可以. . . 结果发现:飞行序号不能同样.. . 于是開始想. ...