POJ 2187 Beauty Contest 凸包
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 27276 | Accepted: 8432 |
Description
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
* Lines 2..N+1: Two space-separated integers x and y specifying coordinate of each farm
Output
Sample Input
4
0 0
0 1
1 1
1 0
Sample Output
2
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; #define M 50005
struct node
{
double x,y;
}A[M],B[M]; double cmp(node a,node b) //先按X排序,其次按Y排序
{
if(a.x != b.x)
return a.x < b.x;
else
return a.y < b.y;
} double dis(node a,node b) //计算两点之间的距离
{
return (b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y);
} double chaji(node a,node b,node c) //叉积,推断方向
{
return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
} int tubao(int n)
{
sort(A,A+n,cmp);
int m=0,i;
for(i=0;i<n;i++) //构建下凸包边
{
while(m>1 && chaji(B[m-2],B[m-1],A[i]) < 0)
m--;
B[m++]=A[i];
} int k=m;
for(i=n-2;i>=0;i--) //构建上凸包边
{
while(m>k && chaji(B[m-2],B[m-1],A[i]) < 0)
m--;
B[m++]=A[i];
} if(n>1) m--;
return m;
} int main()
{
int n;
cin>>n;
int i,j;
for(i=0;i<n;i++)
cin>>A[i].x>>A[i].y; double p=tubao(n);
__int64 max=0,q;
for(i=0;i<p;i++)
for(j=i+1;j<p;j++)
{
q=dis(B[i],B[j]);
if(max<q) max=q;
}
printf("%I64d\n",max); return 0;
}
POJ 2187 Beauty Contest 凸包的更多相关文章
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- POJ 2187 - Beauty Contest - [凸包+旋转卡壳法][凸包的直径]
题目链接:http://poj.org/problem?id=2187 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- POJ 2187 Beauty Contest [凸包 旋转卡壳]
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 36113 Accepted: 11204 ...
- poj 2187 Beauty Contest 凸包模板+求最远点对
题目链接 题意:给你n个点的坐标,n<=50000,求最远点对 #include <iostream> #include <cstdio> #include <cs ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- POJ 2187 Beauty Contest(凸包,旋转卡壳)
题面 Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, earning the ...
- POJ 2187 Beauty Contest(凸包+旋转卡壳)
Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...
- poj 2187:Beauty Contest(计算几何,求凸包,最远点对)
Beauty Contest Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26180 Accepted: 8081 D ...
随机推荐
- python and 和 or
在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样.但是它们并不返回布尔值,而是返回它们实际进行比较的值之一. 例 4.15. and 介绍 >>> 'a' a ...
- python none,null,,,,,类型
内建类型None表示一个空对象,没有方法和属性. None是一个特殊的常量. None和False不同. None不是0. None不是空字符串. None和任何其他的数据类型比较永远返回False. ...
- BZOJ 1621: [Usaco2008 Open]Roads Around The Farm分岔路口
题目 1621: [Usaco2008 Open]Roads Around The Farm分岔路口 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 56 ...
- 【解决ViewPager在大屏上滑动不流畅】 设置ViewPager滑动翻页距离
在项目中做了一个ViewPager+Fragment滑动翻页的效果,在模拟器和小米手机上测试也比较正常.但是换到4.7以上屏幕测试的时候发现老是滑动失效. 因为系统默认的滑动策略是当用户滑动超过半屏之 ...
- JDBC批量运行executeBatch
JDBC运行SQL语句,有两个处理的接口,一个PreparedStatement,Statement,一般操作JDBC比較用得多的还是PreparedStatement 只是在运行批量,Prepare ...
- cocos2d-html5 简易 下拉表单 控件
刚才在CH5的群里问了问 有没有大侠写过 下拉表单控件啊! 没人鸟窝 ,DZ老师表示非常伤心啊 ,于是乎 自己写一个把 共享给大家. 效果图上一个 仅仅实现了一个最最主要的控件 非常eas ...
- [转]数位dp小记
转载自:http://blog.csdn.net/guognib/article/details/25472879 参考: http://www.cnblogs.com/jffifa/archive/ ...
- CPU自制入门——笔记
最近在看日本人的那本书<CPU自制入门>就开始自己捣鼓.把工程方到QuartusII 里面后发现编译不通过,总是提示找不到头文件.工程的目录架构是这个样子的 而.v文件中的.h 是这么包含 ...
- ASP.NET MVC 5 学习教程:Details 和 Delete 方法详解
原文 ASP.NET MVC 5 学习教程:Details 和 Delete 方法详解 在教程的这一部分,我们将研究一下自动生成的 Details 和Delete 方法. Details 方法 打开M ...
- c# 数据库编程(利用DataSet 和 DataAdaper对象操作数据库--跨表操作)
上篇文章我们介绍了如何利用DataSet 和 DataAdaper对象来对单张表进行操作. 本文我们将介绍如何进行跨表操作. 我们通过具体例子方式进行演示,例子涉及到三张表. 1)student表(学 ...