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 ...
随机推荐
- DataReader的例子
前: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataReader对 ...
- android 破解九宫格
将目录切换到D:/adb目录下,命令如下 敲入命令 adb shell 然后回车,可以见到如下结果 再敲入命令cd /data/system然后回车, 再执行 rm gesture.key 回车,搞定 ...
- Asteroids(最小点覆盖)
Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18183 Accepted: 9905 Descri ...
- [置顶] ios 360度旋转效果demo
demo功能:用UIimageView实现360度旋转效果. demo说明:iPhone6.1 测试成功.主要代码在:FVImageSequence.m中.在touchesMoved事件中,通过替换U ...
- 淘宝PK京东:哥刷的不是广告,刷的是存在
冯强/文 (昨晚看阿根廷vs瑞士时手机上敲的,看完太激动忘发了,现配了图发上来) 这两天,关于京东.淘宝渠道下沉的新闻中,两家略带喜感的农村墙体广告在互联网上传播,例如以下图: 京东这图片,越看越像P ...
- randn命令中randn('state')和randn('seed')的不同
(1)RANDN产生正态分布数的语法: RANDN(N) :产生N× N的矩阵,其元素是按正态分布的数组: RANDN(M,N) and RANDN([M,N]):产生M×N的矩阵: RANDN ...
- 微信红包API接口(PHP)
根据微信高级红包接口,开发PHP版本的API接口,现在进行主要代码分析. 红包接口调用请求代码,所有请求参数为必填参数与文档对应: class Wxapi { private $app_id = 'w ...
- POJ 2479 不相交最大子段和
题目意思还是很好理解的,在一个数列中,找出不相交的两个子串使得其和最大. 解题思路: 对于每个i来说,求出[0 ~ i - 1] 的最大子段和以及[i ~ n - 1]的最大子段和,在加起来,求最大的 ...
- 转: AlphaImageLoader简介
Microsoft.AlphaImageLoader是IE滤镜的一种,其主要作用就是对图片进行透明处理.虽然FireFox和IE7以上的IE浏览器已经支持透明的PNG图片,但是就IE5-IE6而言还是 ...
- NOI2015 寿司晚宴
今年NOI确实是在下输了.最近想把当时不会做的题都写一下. 题意 从2到n(500)这些数字中,选若干分给A,若干分给B,满足不存在:A的某个数和B的某个数的GCD不等于1. 对于寿司晚宴这题,标准解 ...