[Luogu P1452] USACO Beauty Contest

洛谷传送门

题目描述

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

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

输入输出格式
输入格式:

第一行:一个整数n

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

输出格式:

一行:最远距离的平方

输入输出样例
输入样例

4
0 0
0 1
1 1
1 0

输出样例

2

解题分析

旋转卡壳板子题……求凸包上最远点对。

代码如下:

#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#define R register
#define IN inline
#define W while
#define gc getchar()
namespace Geometry
{
    using std::max;
    using std::sort;
    #define db int
    #define EPS 1e-8
    #define MX 50005
    struct pt
    {
        db x, y;
    };
    IN pt operator + (const pt &x, const pt &y){return (pt){x.x + y.x, x.y + y.y};} 
    IN pt operator - (const pt &x, const pt &y){return (pt){x.x - y.x, x.y - y.y};}
    IN db operator * (const pt &x, const pt &y){return x.x * y.y - x.y * y.x;}
    IN int sig (const db &x){return (x > -EPS) - (x < EPS);}
    IN bool operator < (const pt &x, const pt &y){return x.x == y.x ? x.y < y.y : x.x < y.x;}
    IN int dist (const pt &x){return x.x * x.x + x.y * x.y;}
    pt con[MX], data[MX];
    db mx;
    int dot, conn, top;
    void get_con()
    {
        sort(data, data + dot);
        for (R int i = 0; i < dot; ++i)
        {
            W(top > 1 && ((con[top - 1] - con[top - 2]) * (data[i] - con[top - 2]) <= 0)) --top;
            con[top++] = data[i];
        }
        int limit = top;
        for (R int i = dot - 2; i >= 0; --i)
        {
            W(top > limit && (con[top - 1] - con[top - 2] )* (data[i] - con[top - 2]) <= 0)--top;
            con[top++] = data[i];
        }
        if(dot >= 2) top--;
        conn = top;
    }
    void rotatingcalipers()
    {
        R int op = 1, ans = 0;
        for (R int i = 0; i < conn; ++i)
        {
            W(((con[i] - con[op]) * (con[i + 1] - con[i])) < ((con[i] - con[op + 1]) * (con[i + 1] - con[i])))
            op = (op + 1) % conn;
            ans = max(ans, max(dist(con[i] - con[op]), dist(con[i + 1] - con[op])));
        }
        printf("%d", ans);
    }
}
using namespace Geometry;
int main()
{
    scanf("%d", &dot);
    for (R int i = 0; i < dot; ++i)
        scanf("%d%d", &data[i].x, &data[i].y);
    get_con();
    rotatingcalipers();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值