HDU 4946 (凸包)

题意是有n个人,每个人有一个坐标和速度,平面上如果的点如果他到达的时间严格的比其他任何人都快,那么这个点就属于他管辖。问每个人的管辖区域是不是无穷大。

显然对于两个速度不同的人,速度小的人就不可能是无穷大。

所以只需要找出速度最大的所有的人。

先求出凸包,凸包的顶点是无穷大,然后找到所有凸包边上的点,这些点也可能是无穷大。

然后暴力枚举所有的速度最大的点,如果和目前认为是无穷大的点重合,显然这两个重合点有相同速度到任何的点都是一样的时间,所以去掉。

坑点是速度是0的点不可能无穷大。

#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef unsigned long long ll;
#define maxn 1111
#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;
    int pos;
    point (double _x = 0, double _y = 0, int _pos = 0) : x(_x), y(_y), pos(_pos) {}
    point operator - (point a) const {
        return point (x-a.x, y-a.y, 0);
    }
    point operator + (point a) const {
        return point (x+a.x, y+a.y, 0);
    }
    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;
    }
};

double cross (point a, point b) {
    return a.x*b.y-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];
bool ans[maxn];

int ConvexHull (point *p, int n) {
    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;
}

bool OnSegment (point p, point a1, point a2) {
    return dcmp (cross (a1-p, a2-p)) == 0 && dcmp (dot (a1-p, a2-p)) < 0;
}

void solve () {
    for (int i = 0; i < m; i++) {
        ans[ch[i].pos] = 1;
    }
    for (int i = 0; i < m; i++) { //凸包边界上的点也算
        for (int j = 0; j < tot; j++) {
            if (OnSegment (p[j], ch[i], ch[(i+1)%m]))
                ans[p[j].pos] = 1;
        }
    }
    for (int i = 0; i < tot; i++) { //凸包顶点或者边界上的点有重合
        if (ans[p[i].pos]) for (int j = 0; j < tot; j++) {
            if (p[i].x == p[j].x && p[i].y == p[j].y && p[i].pos != p[j].pos)
                ans[p[i].pos] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        printf ("%d", (ans[i] == 1));
    }
    printf ("\n");
    return ;
}

int main () {
    //freopen ("in", "r", stdin);
    int kase = 0;
    while (scanf ("%d", &n) == 1 && n != 0) {
        printf ("Case #%d: ", ++kase);
        double Max = 0;
        tot = 0;
        memset (ans, 0, sizeof ans);
        for (int i = 0; i < n; i++) {
            double x, y, v;
            scanf ("%lf%lf%lf", &x, &y, &v);
            if (v == 0)
                continue;
            if (v > Max) {
                Max = v;
                tot = 0;
                p[tot++] = point (x, y, i);
            }
            else if (v == Max) {
                p[tot++] = point (x, y, i);
            }
        }
        if (tot == 0) {
            for (int i = 0; i < n; i++) printf ("0");
            printf ("\n");
            continue;
        }
        m = ConvexHull (p, tot);
        solve ();
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值