hdu4946(凸包)

Area of Mushroom

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


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

题意:一个老师拥有无限的土地,然后他现在有n个学生,分别在坐标xi、yi。速度为vi,对于一个学生,当他到达某点的时间比其他学生时间短时,该土地为他所拥有,问学生中那些人拥有无限土地。

题解:找出速度最大的那些点,跑个凸包,该凸包和普通凸包有点不同,这里三点一线也是成立的,然后凸包上的点就是拥有无限领土的人。

注意:如果最大速度为0的话,那么所有人都不能拥有无限领土。这里有可能存在两个或者几个学生在同一个位置的情况,则这些点都不能拥有无限领土。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
const double eps = 1e-7;
int n;
int len;
struct P{
    int x,y,v,id;
    P(){}
    P(int x,int y,int v,int id):x(x),y(y),v(v),id(id){}
    P operator - (P a){
        return P(x-a.x,y-a.y,0,0);
    }
    int operator ^ (P a){
        return x*a.y-y*a.x;
    }
};

P g[505];
P q[505];
int ma;
int vis[505];
P be[505];

bool cmp(P a,P b){
    return a.x==b.x?a.y<b.y:a.x<b.x;
}

vector<P> tub(){
    vector<P> ans(2*len);
    int cnt = 0;
    for(int i = 0;i < len;i++){
        while(cnt>1&&((ans[cnt-1]-ans[cnt-2])^(q[i]-ans[cnt-2]))<0) cnt--;
        ans[cnt++] = q[i];
    }
    int u = cnt;
    for(int i = len-2;i >= 0;i--){
        while(cnt>u&&((ans[cnt-1]-ans[cnt-2])^(q[i]-ans[cnt-2]))<0) cnt--;
        ans[cnt++] = q[i];
    }
    if(cnt>1) cnt--;
    ans.resize(cnt);
    return ans;
}

void solve(){
    char s[505];
    s[n] = '\0';
    for(int i = 0;i < n;i++){
        s[i] = '0';
    }
    sort(q,q+len,cmp);
    vector<P> ans = tub();
    for(int i = 0;i < ans.size();i++){
        if(vis[ans[i].id]) continue;
        s[ans[i].id] = '1';
    }
    printf("%s\n",s);
}
int main(){
    int I = 0;
    while(scanf("%d",&n)!=EOF&&n){
        ma = 0;
        memset(vis,0,sizeof(vis));
        for(int i = 0;i < n;i++){
            int a,b,c;
            scanf("%d %d %d",&a,&b,&c);
            ma = max(ma,c);
            g[i] = P(a,b,c,i);
        }
        printf("Case #%d: ",++I);
        len = 0;
        if(ma == 0){
            for(int i = 0;i < n;i++){
                printf("0");
            }
            printf("\n");
            continue;
        }

        int cu = 0;
        for(int i = 0;i < n;i++){
            if(g[i].v==ma){
                be[cu++] = g[i];
            }
        }
        sort(be,be+cu,cmp);
        for(int i = 0;i < cu;i++){
            q[len++] = be[i];
            while(i+1<cu&&be[i].x==be[i+1].x&&be[i].y==be[i+1].y){
                vis[be[i].id] = vis[be[i+1].id] = 1;
                i++;
            }
        }
        solve();
    }
    return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值