2014 Multi-University Training Contest 8 1002

 http://acm.hdu.edu.cn/showproblem.php?pid=4946 

题目给你n个点,可以有重复的点。每个点有速度,问它是否是无限点,具体看题目。。

这个题想法很简单,先找出最大的速度,在这里会有重复的最大速度。先去重,然后把所有最大速度的点求凸包,凸包上的点的位置为1,当然,记得标记之前去重的点,因为去重的点也有可能在凸包上,这些点不能为1。现在很清晰了。

第一次敲凸包,刚开始看不懂凸包的模板,自己太弱,要再努力啊。

Area of Mushroom

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


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 (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
 

Source
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#define MAXN 1000

using namespace std;

struct P{int x,y,v,order;}point[MAXN],tubao[MAXN];
int pos[MAXN];

bool same(P a,P b){
    if(a.x==b.x&&a.y==b.y&&a.v==b.v)
        return true;
    return false;
}

bool cmp(P a, P b){
    return a.v>b.v;
}

bool cmp_x(const P& p, const P& q){
    if(p.x!=q.x) return p.x<q.x;
    return p.y<q.y;
}

P jian(P a, P b){
    P c;
    c.x=a.x-b.x;
    c.y=a.y-b.y;
    return c;
}

int chaji(P a, P b) { return (a.x*b.y)-(a.y*b.x); }

vector<P> convex_hull(P* ps, int n){
    sort(ps,ps+n,cmp_x);
    int k = 0;
    vector<P> qs(n*2);

    for(int i=0;i<n;i++){
        while(k>1&& chaji ( jian(qs[k-1],qs[k-2]), jian(ps[i],qs[k-1]) ) < 0) k--;
        qs[k++]=ps[i];
    }

    for(int i=n-2,t=k;i>=0;i--){
        while(k>t&& chaji ( jian(qs[k-1],qs[k-2]), jian(ps[i],qs[k-1]) ) < 0) k--;
        qs[k++]=ps[i];
    }
    qs.resize(k-1);
    return qs;
}

int main()
{
    int m=1,n;
    while( ~scanf("%d",&n) ) {
        memset(pos,0,sizeof(pos));
        if(n == 0) break;
        for(int i = 0; i < n; i++) {
            scanf("%d%d%d",&point[i].x,&point[i].y,&point[i].v);
            point[i].order=i;
        }

        printf("Case #%d: ",m++);

        sort(point,point+n,cmp);

        int v=point[0].v;

        //如果最大的v就是0,则所有都为0
        if(v==0){
            for(int i=0;i<n;i++)
                printf("0");
            printf("\n");
            continue;
        }


        for(int i = 0; i < n; i++){
            //cout<<point[i].x<<" "<<point[i].y<<" "<<point[i].v<<" "<<point[i].order<<endl;
            for(int j = 0; j < n && j != i; j++){
                if(same(point[i],point[j])) {
                    point[j].v=-1000000;
                    pos[point[j].order]=-1;
                    pos[point[i].order]=-1;
                }
            }
        }



        int k=0;
        for(int i = 0; i < n; i++){
            if(point[i].v==v) tubao[k++]=point[i];
        }

        if(k==1){
            if(pos[point[0].order]!=-1)
                pos[point[0].order]=1;
            else pos[point[0].order]=0;

            for(int i = 0; i < n; i++)
                if(pos[i]==-1) pos[i]=0;
            for(int i = 0; i < n; i++)
                printf("%d",pos[i]);
            printf("\n");
            continue;
        }

        vector<P> p=convex_hull(tubao,k);

        for(int i = 0; i < p.size(); i++){
            if(pos[p[i].order]!=-1) pos[p[i].order]=1;
        }

        for(int i=0;i<n;i++)
            if(pos[i]==-1) pos[i]=0;

        for(int i = 0; i < n; i++)
            printf("%d",pos[i]);
        printf("\n");
    }
    return 0;
}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值