HDU 4946 Area of Mushroom(凸包)

传送门

Teacher Mai has a kingdom with the infinite area.

He has n students guarding the kingdom.

The i-th student stands at the position (x i,y i), and his walking speed is v i.

If a point can be reached by a student, and the time this student walking to this point is strictly 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 x i,y i,v i(0<=|x i|,|y i|,v i<=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

题目大意:

n 个学生,每个学生有坐标 (x,y),还有一个速度 v ,如果这个人到达一个整数点比其他人到达的快(严格的快),如果这样的点是无穷的输出 1,否则输出 0

解题思路

显然,达到无穷的点的学生速度一定是最快的,那么我们首先找出速度最快的点,然后在进行判断,发现如果其中一个点被其他点包围了,那么这样的点也不是无穷的,到这里就想到,只有凸包上的点才是符合条件的。有如下几种情况。

情况1: 当最快速度是 0 的话,他根本不会到达任何一个点,所以都输出 0
情况2: 当最快的点在凸包上的边上,我们需要判断,用叉积判断是不是共线。
情况3: 还有重点的时候,因为是严格最快的,所以当有重点,而且速度最快的时候,这样的点也是不符合的,输出 0

代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct Point{
    int x,y,w,flag,ind;
    bool operator <(const struct Point &tmp)const{
        if(x-tmp.x == 0) return y<tmp.y;
        return x<tmp.x;
    }
    bool operator ==(const struct Point &tmp)const{
        return x==tmp.x&&y==tmp.y&&w==tmp.w;
    }

}d[505],st[505];
bool cmp(Point a,Point b){
    return a.w>b.w;
}
int XMulti(Point a, Point b, Point c)///ac X ab
{
    return (c.x-a.x)*(b.y-a.y) - (b.x-a.x)*(c.y-a.y);
}

int ConvexHull(Point *p, int n, Point *st)///凸包
{
    sort(p, p+n);
    n=unique(p, p+n)-p;
    int m = 0;
    for(int i=0; i<n; i++){
        while(m>1 && XMulti(st[m-2],p[i],st[m-1])<=0) m--;
        st[m++] = p[i];
    }
    int k = m;
    for(int i=n-2; i>=0; i--){
        while(m>k && XMulti(st[m-2],p[i],st[m-1])<=0) m--;
        st[m++] = p[i];
    }
    if(n > 1) m--;
    return m;
}
int ans[505];
int main()
{
    int n, cas=1;
    while(~scanf("%d",&n)){
        if(n == 0)break;
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&d[i].x,&d[i].y,&d[i].w);
            d[i].ind=i;
        }
        for(int i=0; i<n; i++) d[i].flag=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].w==d[j].w) d[i].flag=d[j].flag=1;
        sort(d,d+n,cmp);
        printf("Case #%d: ",cas++);
        if(d[0].w == 0){
            for(int i=0;i<n;i++) putchar('0');
            puts("");
            continue;
        }
        memset(ans, 0, sizeof ans);
        int end2 = n;
        for(int i=1; i<n; i++){
            if(d[i].w != d[i-1].w){
                end2=i;
                break;
            }
        }
        int cnt = ConvexHull(d, end2, st);
        for(int i=0; i<end2; i++)
            for(int j=0; j<cnt; j++)
                if(!d[i].flag&&XMulti(d[i],st[j],st[(j+1)%cnt])==0) ans[d[i].ind] = 1;
        for(int i=0; i<n; i++) printf("%d",ans[i]);
        puts("");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值