题目背景

此处省略1W字^ ^

题目描述

贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”。因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意。世界将被表示成一个二维平面,每个农场位于一对整数坐标(x,y),各有一个值范围在-10000…10000。没有两个农场共享相同的一对坐标。

尽管贝西沿直线前往下一个农场,但牧场之间的距离可能很大,所以她需要一个手提箱保证在每一段旅程中她有足够吃的食物。她想确定她可能需要旅行的最大可能距离,她要知道她必须带的手提箱的大小。帮助贝西计算农场的最大距离。

输入输出格式

输入格式:

第一行:一个整数n

第2~n+1行:xi yi 表示n个农场中第i个的坐标

输出格式:

一行:最远距离的[b]平方[/b]

输入输出样例

输入样例#1:

4
0 0
0 1
1 1
1 0
输出样例#1:

2

说明

NONE

想了一下还是写写旋转卡壳吧,

毕竟做题功利性不能太强,

但是。。。。

旋转卡壳居然和暴力一样快,,,,,,,,,,,,,,,,,,,,

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define vec point
using namespace std;
const double eps=1e-;
const int MAXN=;
int n;
void read(int &n)
{
char c='+';int x=;bool flag=;
while(c<''||c>''){c=getchar();if(c=='-')flag=;}
while(c>=''&&c<=''){x=x*+(c-);c=getchar();}
flag==?n=-x:n=x;
}
inline int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x>?:-;
}
struct point
{
double x,y;
inline point(double x=,double y=):x(x),y(y){};
}p[MAXN],ch[MAXN];
vec operator - (vec a,vec b) {return vec(a.x-b.x,a.y-b.y);}
vec operator + (vec a,vec b) {return vec(a.x+b.x,a.y+b.y);}
vec operator == (vec a,vec b){return (dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==);}
int comp(const point &a,const point &b)
{
if(a.x==b.x) return a.y<b.y;
else return a.x<b.x;
}
int stack[MAXN];
double cross(vec a,vec b){return a.x*b.y-a.y*b.x;}
int convex_hull()
{
sort(p+,p+n+,comp);
int top=;
for(int i=;i<=n;i++)
{
while(top>&& dcmp(cross(ch[top-]-ch[top-], p[i]-ch[top-]))<=) top--;
ch[top++]=p[i];
}
int tmp=top+;
for(int i=n-;i>=;i--)
{
while(top+>tmp&& dcmp(cross(ch[top-]-ch[top-], p[i]-ch[top-]))<=) top--;
ch[top++]=p[i];
}
if(n>) top--;
return top;
}
int dis(point a,point b)
{
return ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int num=;
int ans=;
int Cross(point a,point b,point c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
inline void xzqk()
{
if(num==) ans=dis(ch[],ch[]);
int j=;
for(int i=;i<=num;i++)
{
while(Cross(ch[i],ch[i+],ch[j])<Cross(ch[i],ch[i+],ch[j+]))
j=(j+)%num;// 防止溢出
ans=max(ans,max(dis(ch[i],ch[j]),dis(ch[i+],ch[j])));
}
}
int main()
{
//freopen("fc.in","r",stdin);
//freopen("fc.out","w",stdout);
read(n);
//ios::sync_with_stdio(0);
for(int i=;i<=n;i++)
{
double a,b;
cin>>a>>b;
p[i]=point(a,b);
}
num=convex_hull();
xzqk(); printf("%d",ans);
return ;
}

P1452 Beauty Contes(旋转卡壳版)的更多相关文章

  1. P1452 Beauty Contest 旋转卡壳

    \(\color{#0066ff}{题目描述}\) 贝茜在牛的选美比赛中赢得了冠军"牛世界小姐".因此,贝西会参观N(2 < = N < = 50000)个农场来传播善 ...

  2. poj2187 Beauty Contest(旋转卡壳)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Beauty Contest Time Limit: 3000MS   Memor ...

  3. poj 2187:Beauty Contest(旋转卡壳)

    Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 32708   Accepted: 10156 Description Bes ...

  4. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  5. poj 2187 Beauty Contest——旋转卡壳

    题目:http://poj.org/problem?id=2187 学习材料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  6. P1452 Beauty Contes

    题目背景 此处省略1W字^ ^ 题目描述 贝茜在牛的选美比赛中赢得了冠军”牛世界小姐”.因此,贝西会参观N(2 < = N < = 50000)个农场来传播善意.世界将被表示成一个二维平面 ...

  7. poj 2187 Beauty Contest —— 旋转卡壳

    题目:http://poj.org/problem?id=2187 学习资料:https://blog.csdn.net/wang_heng199/article/details/74477738 h ...

  8. 【洛谷 P1452】 Beauty Contest (二维凸包,旋转卡壳)

    题目链接 旋转卡壳模板题把. 有时间再补总结吧. #include <cstdio> #include <cmath> #include <algorithm> u ...

  9. luogu P1452 [USACO03FALL]Beauty Contest G /【模板】旋转卡壳

    LINK:旋转卡壳 如题 是一道模板题. 容易想到n^2暴力 当然也能随机化选点 (还真有人过了 考虑旋转卡壳 其实就是对于某个点来说找到其最远的点. 在找的过程中需要借助一下个点的帮助 利用当前点到 ...

随机推荐

  1. (手冊)Animation 之 使用Animation View

    观看游戏物体上的动画(Viewing Animations on a GameObject) Animation View 是与 Hierarchy View.Scene View和Inspector ...

  2. Android 的Recovery机制

    Android 的Recovery机制 文件夹 1. 系统的启动模式 1 1.1 Android系统的启动模式 1 1.2 系统的启动模式 2 2. Recovery模式中的三个部分 3 3. Rec ...

  3. POJ 1496 POJ 1850 组合计数

    Code Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8256 Accepted: 3906 Description Tran ...

  4. UVALive 4192/HDU 2959 Close Enough Computations 数学

    Close Enough Computations Problem Description The nutritional food label has become ubiquitous. A sa ...

  5. POJ 3188暴搜

    题意: 思路: 裸的暴搜 --. 但是要注意如果你不用所有的按键就能输出最优解的话一定要把所有的字母都安排到一个位置-. 我的一群PE就是这么来的-- 为什么写的人这么少-- // by Sirius ...

  6. 配置 NTP 时间服务器

    对于我们当前这种案例,主要目标是把 z01 这台服务器设置为时间服务器,剩下的 z02,z03 这两台机器同步 z01 的时间,我们需要这样做的原因是因为,整个集群架构中的时间,要保持一致. ** 检 ...

  7. android常用自动化测试框架

    目录: Monkey MonkeyRunner Instrumentation UiAutomator Espresso Selendroid Robotium Athrun Appium Monke ...

  8. 解码URLDecode和编码URLEnCode

    在前台往后台传递参数的时候,在前台进行编码,在后台接收参数的时候,用Decode进行解码: 如果url中包含特殊字符如:&.html标签 <tr><td>等导致url无 ...

  9. [Java] Protect, Private and Public的区别

    Java中的private.protected.public和default的区别 (2014-03-21 22:29:14) 转载▼ 标签: java java修饰符 it   (1)对于publi ...

  10. XShell与虚拟机连接的IP问题

    这几天在Xshell连接虚拟机这个问题上头疼了好长时间,原因是我在虚拟机内的eth0网卡没有分配IP地址,从而导致无法连接XShell,今天解决了这个问题,做一下记录. 首先我使用的是微软的Hyper ...