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 ...
随机推荐
- maven GroupID和ArtifactID填什么
GroupID是项目组织唯一的标识符,实际对应JAVA的包的结构,是main目录里java的目录结构. ArtifactID就是项目的唯一的标识符,实际对应项目的名称,就是项目根目录的名称.一般Gro ...
- nginx 配置日志
http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $r ...
- ligh@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3
ligh@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.3
- android 仿小米icon处理,加阴影和边框
本人自己在做一个launcher,所以须要处理icon,加阴影和边框等.这仅仅是一种处理方法,其它的处理方法类似. 源码: https://github.com/com314159/LauncherI ...
- LoaderManager使用具体解释(三)---实现Loaders
这篇文字将介绍Loader<D>类,而且介绍自己定义Loader的实现.这是本系列的第三篇文章. 一:Loaders之前世界 二:了解LoaderManager 三:实现Loaders 四 ...
- int *p = NULL 和 *p = NULL(转载)
int *p = NULL 和 *p = NULL int *p = NULL; 这时候我们用编译器查看p的值为0x00000000.这句话的意思是定义一个指针变量p,其指向内存里面保存的是 ...
- jq商品展示图放大镜 and 原生js和html5写的放大镜效果 ~~效果不错
<!DOCTYPE HTML><html lang="en-US"><head> <meta charset="UTF-8&qu ...
- Linux下的在线播放神器
Linux下的在线播放神器:一个是Amarok缺点是,每个音乐源都要更新后才能播放. 在一个就是中国造的:linux deepin下的深度音乐,缺点就是连不上.反正我是连不上
- SilkTest天龙八部系列6-用open agent进行测试
SilkTest支持两种测试模式,一种是用classic agent,另一种就是用我们今天要介绍的open agent. open agent可以提供和classic agent差不多的录制回放功能. ...
- 正态分布(Normal distribution)又名高斯分布(Gaussian distribution)
正态分布(Normal distribution)又名高斯分布(Gaussian distribution),是一个在数学.物理及project等领域都很重要的概率分布,在统计学的很多方面有着重大的影 ...