Beauty Contest 凸包+旋转卡壳法
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 27507 | Accepted: 8493 |
Description
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
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdio.h>
using namespace std;
#define PI 3.1415926535898
struct point
{
int x,y;
};
point p[],res[];
int n,top;
int Dist(const point &arg1, const point &arg2)
{
return (arg1.x - arg2.x)*(arg1.x - arg2.x) + (arg1.y - arg2.y)*(arg1.y - arg2.y);
}
bool multi(point p0,point p1,point p2)
{
return (p1.x-p0.x)*(p2.y-p0.y)>(p2.x-p0.x)*(p1.y-p0.y);
}
bool cmp(const point &a,const point &b)
{
point temp=p[];
double xmt=(a.x-temp.x)*(b.y-temp.y)-(b.x-temp.x)*(a.y-temp.y);
if(xmt) //向量不共线就按逆时针旋转
return xmt>;
return Dist(a,temp)>Dist(b,temp);//向量共线取最长的。
}
void graham()//p[0]是左下角的元素
{
res[]=p[];
sort(p+,p+n,cmp);//按照极角排序
res[]=p[];
res[]=p[];
top=; for(int i=; i<n; i++)
{
while(top>&&multi(p[i],res[top],res[top-]))
top--;
res[++top]=p[i];
}
}
int cross(point a,point b,point o)
{
return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
}
void rotating_calipers()
{
int q=,ans=;
res[++top]=res[];
for(int p=;p<n;p++)
{
while(cross(res[p+],res[q+],res[p])>cross(res[p+],res[q],res[p]))
q=(q+)%top;
ans=max(ans,max(Dist(res[p],res[q]),Dist(res[p+],res[q+])));
}
cout<<ans<<endl;
}
int main()
{
int i,mina,m;
point temp;
while(~scanf("%d",&n))
{
scanf("%d%d",&p[].x,&p[].y);
mina=;
for(i=; i<n; i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
if(p[i].y<p[mina].y||(p[i].y==p[mina].y&&p[i].x<p[mina].x))
mina=i;
}
swap(p[].x,p[mina].x),swap(p[].y,p[mina].y);
graham();
rotating_calipers();
}
}
Beauty Contest 凸包+旋转卡壳法的更多相关文章
- 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 凸包+旋转卡壳
xuán zhuǎn qiǎ ké模板题 是这么读吧(≖ ‿ ≖)✧ 算法挺简单:找对踵点即可,顺便更新答案. #include<cstdio> #include<cstring&g ...
- 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(旋转卡壳)
http://poj.org/problem?id=2187 显然直径在凸包上(黑书上有证明).(然后这题让我发现我之前好几次凸包的排序都错了QAQ只排序了x轴.....没有排序y轴.. 然后本题数据 ...
- POJ-2187 Beauty Contest,旋转卡壳求解平面最远点对!
凸包(旋转卡壳) 大概理解了凸包A了两道模板题之后在去吃饭的路上想了想什么叫旋转卡壳呢?回来无聊就搜了一下,结果发现其范围真广. 凸包: 凸包就是给定平面图上的一些点集(二维图包),然后求点集组成的 ...
- POJ2187 Beauty Contest(旋转卡壳)
嘟嘟嘟 旋转卡壳模板题. 首先求出凸包. 然后\(O(n ^ 2)\)的算法很好想,但那就不叫旋转卡壳了. 考虑优化:直观的想是在枚举点的时候,对于第二层循环用二分或者三分优化,但实际上两点距离是不满 ...
- POJ2187 Beauty Contest (旋转卡壳算法 求直径)
POJ2187 旋转卡壳算法如图 证明:对于直径AB 必然有某一时刻 A和B同时被卡住 所以旋转卡壳卡住的点集中必然存在直径 而卡壳过程显然是O(n)的 故可在O(n)时间内求出直径 凸包具有良好的性 ...
- poj 2187 Beauty Contest(二维凸包旋转卡壳)
D - Beauty Contest Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- input标签新增属性
<input list='list_t' type="text" name='user' placeholder='请输入姓名' value="" / ...
- import和require
es6 的 import 语法跟 require 不同,而且 import 必须放在文件的最开始,且前面不允许有其他逻辑代码,这和其他所有编程语言风格一致. import不同与require,它是编译 ...
- 如何写SysV服务管理脚本
本文目录: 1.1 SysV脚本的特性1.2 SysV脚本要具备的能力1.3 start函数分析1.4 stop函数分析1.5 reload函数分析1.6 status.restart.force-r ...
- CCNP-3.vlan间路由及三层交换机的配置
- 团队作业4——第一次项目冲刺(ALpha版本)第四天
一.Daily Scrum Meeting照片 二.燃尽图 三.项目进展 1.界面 完善了昨天的的代码---前端的HTML页面设计 2.功能 完成后台数据处理的全部基本功能: a.数据结构设计及数据交 ...
- 201521123036 《Java程序设计》第5周学习总结
本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 接口(interface):对行为的抽象 方法声明和常量值的集合 方法声明:接口中所有 ...
- 201521123050《Java程序设计》第3周学习总结
1. 本周学习总结 2. 书面作业 1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; p ...
- 201521123055《Java程序设计》第1周学习总结
1. 本章学习总结 (1)JAVA环境配置(JDK,JVM) (2)编写简易程序熟练代码结构 2. 书面作业 1.为什么java程序可以跨平台运行?执行java程序的步骤是什么? JAVA程序需要 ...
- 201521123076 《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) ...
- 201521123064 《Java程序设计》第14周学习总结
本次作业参考文件 数据库PPT MySql操作视频与数据库相关jar文件请参考QQ群文件. 1. 本章学习总结 1.1 以你喜欢的方式(思维导图.OneNote或其他)归纳总结数据库相关内容. 1.数 ...