HDU 4946 Area of Mushroom (凸包 思维)

77 篇文章 8 订阅
22 篇文章 0 订阅

Area of Mushroom

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 3523    Accepted Submission(s): 809


Problem Description
Teacher Mai has a kingdom with the infinite area.
He has n students guarding the kingdom.
The i-th student stands at the position (xi,yi), and his walking speed is vi.
If a point can be reached by a student, and the time this student walking to this point isstrictly less than other students, this point is in the charge of this student.
For every student, Teacher Mai wants to know if the area in the charge of him is infinite.
 
Input
There are multiple test cases, terminated by a line "0".
For each test case, the first line contains one integer n(1<=n<=500).
In following n lines, each line contains three integers xi,yi,vi(0<=|xi|,|yi|,vi<=10^4).
 
Output
For each case, output "Case #k: s", where k is the case number counting from 1, and s is a string consisting of n character. If the area in the charge of the i-th student isn't infinite, the i-th character is "0", else it's "1".
 
Sample Input
  
  
3 0 0 3 1 1 2 2 2 1 0
 
Sample Output
  
  
Case #1: 100
 
Source
2014 Multi-University Training Contest 8

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946

题目大意:n个点每个点有个速度,若某个点到别的无穷多的点的时间比其他所有点都短则其可以控制无穷大的区域,输出1否则输出0

题目分析:显然只有速度最大的点才有可能控制无穷大的区域,对速度最大的那些点求凸包,求得是非纯净凸包(包含共线点),只有在凸包上的点才有可能满足条件,注意可能有坐标和速度都相同的两个点,此时这两个点相互制约都不能控制无穷大的区域,还有就是速度全为0时,则均不能控制无穷大的区域,于是得到求解过程:
1.得到最大速度,若最大速度为0则输出n个0
2.去除最大速度下的重点(将重点的速度设为0即可),并标记重点
3.对去重后的拥有最大速度的那些点求非纯净凸包(这里需要用上下凸包来求,不能直接逆时针扫一圈)
4.在非纯净凸包上的且没有被标记为重点的那些点可以控制无穷大的区域
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const MAX = 505;

struct POINT {
    int x, y, v, id;
}d[MAX], p[MAX], stk[MAX], base;
int n, cnt, top;

bool ok[MAX], same[MAX];

int getDist(POINT p1, POINT p2) {
    return (p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y);
}

int getCross(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(POINT p1, POINT p2) {
    if (getCross(base, p1, p2) == 0) {
        return getDist(base, p1) < getDist(base, p2);
    }
    if (getCross(base, p1, p2) > 0) {
        return true;
    }
    return false;
}

void getBase() {
    base = p[0];
    int pos = 0;
    for (int i = 1; i < cnt; i ++) {
        if (p[i].y < base.y || (p[i].y == base.y && p[i].x < base.x)) {
            base = p[i];
            pos = i;
        }
    }
    swap(p[0], p[pos]);
}

void getConvex() {
    stk[0] = p[0];
    if (cnt == 1) {
        top = 0;
        return;
    }
    sort(p + 1, p + cnt, cmp);
    stk[1] = p[1];
    top = 1;
    for (int i = 2; i < cnt; i ++) {
        while (top > 0 && getCross(stk[top - 1], stk[top], p[i]) < 0) {
            top --;
        }
        stk[++ top] = p[i];
    }
    int len = top;
    stk[++ top] = p[cnt - 2];
    for (int i = cnt - 3; i >= 0; i --) {
        while (top != len && getCross(stk[top - 1], stk[top], p[i]) < 0) {
            top --;
        }
        stk[++ top] = p[i];
    }
    if (cnt > 1) {
        top --; 
    }
}

int main() {
    int ca = 1;
    while(scanf("%d", &n) != EOF && n) {
        printf("Case #%d: ", ca ++);
        memset(ok, false, sizeof(ok));
        memset(same, false, sizeof(same));
        int ma = 0;
        for (int i = 0; i < n; i ++) {
            scanf("%d %d %d", &d[i].x, &d[i].y, &d[i].v);
            d[i].id = i;
            ma = max(ma, d[i].v);
        }
        if (ma == 0) {
            for (int i = 0; i < n; i ++) {
                printf("0");
            }
            printf("\n");
            continue;
        }
        cnt = 0;
        for (int i = 0; i < n; i ++) {
            for (int j = i + 1; j < n; j ++) {
                if (d[i].x == d[j].x && d[i].y == d[j].y && d[i].v == d[j].v) {
                    d[j].v = 0;
                    same[i] = true;
                }
            }
        }
        for (int i = 0; i < n; i ++) {
            if (d[i].v == ma) {
                p[cnt ++] = d[i];
            }
        }
        getBase();
        getConvex();
        for (int i = 0; i <= top; i ++) {
            ok[stk[i].id] = !same[stk[i].id];
        }
        for (int i = 0; i < n; i ++) {
            printf("%d", ok[i]);
        }
        printf("\n");
    }
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值