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 ...
随机推荐
- AnyEvent::HTTP 介绍
AnyEvent::HTTP - simple but non-blocking HTTP/HTTPS client 一个简单的非堵塞的 HTTP/HTTPS 客户端: use AnyEvent::H ...
- BZOJ 1601 [Usaco2008 Oct]灌水
1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec Memory Limit: 162 MB Description Farmer John已经决定把水灌到他的n(1 ...
- ORA-00845 Oracle 启不来修改 MEMORY_TARGET
1.内存减小导致Oracle启动不了 Last login: Sun Nov 4 15:09:06 2012 from 192.168.5.222 [oracle@h1 ~]$ sqlplus ...
- iOS/Xcode异常:reason = “The model used to open the store is incompatible with the one used to create the store”
reason=The model used to open the store is incompatible with the one used to create the store 出现上述异常 ...
- Codeforces 41D Pawn 简单dp
题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...
- - 通过 UIBezierPath 做一个中空的扫描器
今天在公司的代码里看到通过 UIBezierPath 绘制 CALayer 然后实现中空的正方形,感觉还挺有意思的,简单记录一下 UIBezierPath 这个东西. 一条线 我们自定义一个 Bezi ...
- 警惕 MySql 更新 sql 的 WHERE 从句中的 IN() 子查询时出现的陷阱
mer_stage 表有 216423 条记录,DDL: CREATE TABLE `mer_stage` ( `STAGE_ID` int(11) NOT NULL AUTO_INCREMENT, ...
- 【转】理解RESTful架构
[转]理解RESTful架构 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件"采用客户端/服务器模式,建立在分布式体系上,通过互联网通信,具有高延时( ...
- Xcode使用source control 时提示the server certificate failed to verify 的解决办法
wusipingdeMacBook-Pro:~ railgun$ wusipingdeMacBook-Pro:~ railgun$ svn ls https://13.13.13.134:8443/s ...
- opencv kmeans 图像分割
利用kmeans算法,将彩色图像的像素点作为样本,rgb值作为样本的属性, 对图像所有的像素点进行分类,从而实现对图像中目标的分割. c++代码(openCV 2.4.11) Scalar color ...