POJ 2187: Beauty Contest(旋转卡)
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 27218 | Accepted: 8410 |
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
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(旋转卡)的更多相关文章
- poj 2187:Beauty Contest(旋转卡壳)
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 32708 Accepted: 10156 Description Bes ...
- poj 2187 Beauty Contest——旋转卡壳
题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- poj 2187 Beauty Contest —— 旋转卡壳
题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- poj 2187 Beauty Contest(凸包求解多节点的之间的最大距离)
/* poj 2187 Beauty Contest 凸包:寻找每两点之间距离的最大值 这个最大值一定是在凸包的边缘上的! 求凸包的算法: Andrew算法! */ #include<iostr ...
- 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 Time Limit: 3000MS Memory Limit: 65536K Description Bessie, Farm ...
- 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 ...
随机推荐
- 【Android基础】listview控件的使用(2)-------继承自ListActivity的普通listview
由于listview在android控件中的重要性,所以android为我们直接封装了一个类ListviewActivity,直接将listview封装在了activity之中,在本篇中,我将介绍在L ...
- ubuntu 下安装crypto
直接运行apt-get install python-crypto 就好了
- uva 10831 - Gerg's Cake(勒让德符号)
题目链接:uva 10831 - Gerg's Cake 题目大意:给定a和p.p为素数,问说是否存在x,使得x2≡a%p 解题思路:勒让德记号,推断ap−12≡1%p #include <cs ...
- Oracle之Check约束实例具体解释
Oracle | PL/SQL Check约束使用方法具体解释 1. 目标 实例解说在Oracle中怎样使用CHECK约束(创建.启用.禁用和删除) 2. 什么是Check约束? CHECK约束指在表 ...
- java使用Base64编码和解码的图像文件
1.编码和解码下面的代码示例看: import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import j ...
- 它们的定义PropertyPlaceHolder无法完成更换任务
Spring默认PropertyPlaceholderConfigurer只能加载properties格风格简介,现在,我们需要能够从类的完整支持允许似hadoop格风格xml配置文件读取配置信息,并 ...
- SDL2来源分析7:演出(SDL_RenderPresent())
===================================================== SDL源代码分析系列文章上市: SDL2源码分析1:初始化(SDL_Init()) SDL2 ...
- poj3624Charm Bracelet
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23025 Accepted: 103 ...
- Oracle 实现 mysql 的 find_in_set 排序!
oracle 实现类似MYSQL的 find_in_set 排序,函数 decode: select * from tb_info_game where gameid in(23,20,19,26,1 ...
- jQuery地图热点效应-后在弹出的提示鼠标层信息
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...