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. uitableView 选择跳过后, 跳回 颜色变化 问题

    今天遇到这个问题  谁也因此没有满足这方面的需求 今天会见 网上办理登机手续 未找到 好 我只能说自己的问题 但 幸好,kai哥 就攻克了 ! 就是在- (void)tableView:(UITabl ...

  2. struts2于validate要使用

    package com.test.action; import com.opensymphony.xwork2.ActionSupport; import com.test.model.User; p ...

  3. SQL Server 2008 R2 跟踪标志

    原文:SQL Server 2008 R2 跟踪标志 跟踪标志用于临时设置特定服务器的特征或关闭特定行为.例如,如果启动 SQL Server 的一个实例时设置了跟踪标志 3205,将禁用磁带机的硬件 ...

  4. Swift编程语言学习1.3——类型安全和投机型

    Swift 是类型安全(type safe )语言.类型安全的语言可以让你清楚地知道代码被处理值类型.假设你需要一个代码String.你绝对不能进去一个不小心传球Int. 因为 Swift 它是类型安 ...

  5. java IdentityHashMap 与HashMap

    这两个map的主要区别在于,比较key值什么时候: IdentityHashMap我觉得当k1 == k2 时刻key值一样的 HaspMap觉得k1 == null ? k2 == null:k1. ...

  6. 【ASP.NET】判断访问网站的客户端是PC还是手机

    原文:[ASP.NET]判断访问网站的客户端是PC还是手机 主要就是通过客户端传递的User-agent来判断访问网站的客户端是PC还是手机,.NET中就是Request.ServerVariable ...

  7. 【转】Android内存机制分析2——分析APP内存使用情况

    上面一篇文章说了Android应用运行在dalvik里面分配的堆和栈内存区别,以及程序中什么代码会在哪里运行.今天主要是讲解一下Android里面如何分析我们程序内存使用情况.以便后续可以分析我们程序 ...

  8. 正则、grep、sed、awk

    每次用到正则都要蛋疼一下,索性总结一下在这里. 正则 正則表達式主要分为基础正则和扩展正则.注意,正则和一般命令行输入的命令的通配符不同.正则仅仅使用于支持这样的表示法的工具,如:vi,grep,se ...

  9. Java得到年在一个季度的错误的第一天

    1.错误叙述性说明 Exception in thread "main" java.lang.IllegalArgumentException: Cannot format giv ...

  10. 如何设置eclipse在默认模式下打开文件

    如何设置eclipse在默认模式下打开文件 打开eclipse.选择例如以下:windows --> preferences --> General --> Editors --&g ...