HDU 2202 (旋转卡壳)

#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef unsigned long long ll;
#define maxn 51111
#define pi acos (-1)
#define rotate Rotate

const double eps = 1e-8;
int dcmp (double x) {
    if (fabs (x) < eps)
        return 0;
    else return x < 0 ? -1 : 1;
}
struct point {
    double x, y;
    point (double _x = 0, double _y = 0) : x(_x), y(_y) {}
    point operator - (point a) const {
        return point (x-a.x, y-a.y);
    }
    point operator + (point a) const {
        return point (x+a.x, y+a.y);
    }
    bool operator < (const point &a) const {
        return x < a.x || (x == a.x && y < a.y);
    }
    bool operator == (const point &a) const {
        return dcmp (x-a.x) == 0 && dcmp (y-a.y) == 0;
    }
};

point operator * (point a, double p) {
    return point (a.x*p, a.y*p);
}
double cross (point a, point b) {
    return (double)a.x*b.y-(double)a.y*b.x;
}
double dot (point a, point b) {
    return a.x*b.x + a.y*b.y;
}

int n, m, tot;
point p[maxn], ch[maxn];

int ConvexHull () {
    sort (p, p+n);
    int m = 0;
    for (int i = 0; i < n; i++) {
        while (m > 1 && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0)
            m--;
        ch[m++] = p[i];
    }
    int k = m;
    for (int i = n-2; i >= 0; i--) {
        while (m > k && cross (ch[m-1]-ch[m-2], p[i]-ch[m-1]) <= 0)
            m--;
        ch[m++] = p[i];
    }
    if (n > 1)
        m--;
    return m;
}

double rotate_calipers () {
    if (m == 1 || m == 2)
        return 0;
    double ans = 0;
    int cur = 1;
    for (int add = 1; add < m; add++) {
        for (int i = 0; i < m; i++) {
            while (cross (ch[i]-ch[(i+add)%m], ch[(cur+1)%m]-ch[cur]) < 0)
                cur = (cur+1)%m;
            double res = max (cross (ch[(i+add)%m]-ch[i], ch[cur]-ch[i]), cross (ch[(i+add)%m]-ch[i], ch[(cur+1)%m]-ch[i]));
            ans = max (ans, res);
        }
    }
    return ans/2.0;
}

int main () {
    //freopen ("in", "r", stdin);
    while (scanf ("%d", &n) == 1 ) {
        for (int i = 0; i < n; i++) {
            scanf ("%lf%lf", &p[i].x, &p[i].y);
        }
        m = ConvexHull ();
        printf ("%.2f\n", rotate_calipers ());
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值