首页 > 其他 > 详细

Assign the task---hdu3974

时间:2015-08-01 18:52:26      阅读:380      评论:0      收藏:0      [点我收藏+]

题目链接

题意就是:公司有n个员工,关系有n-1个,T x y 代表把工作y交给员工x;

员工可以把工作交给下属;

本来是线段树的题,但是我真心看不懂,所以就找了个能看懂的方法了

 

技术分享
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 50050

int f[N];
struct node
{
    int task, order;
}a[N];
int Query(int x)
{
    int order = -1, ans = -1;
    while(x != 0)
    {
        if(a[x].order > order)
        {
            ans = a[x].task;
            order = a[x].order;
        }
        x = f[x];
    }
    return ans;
}

int main()
{
    int T, n, m, t=1, x, y;
    char s[10];
    scanf("%d", &T);
    while(T--)
    {

        scanf("%d", &n);
        memset(a, -1, sizeof(a));
        memset(f, 0, sizeof(f));
        for(int i=1; i<=n-1; i++)
        {
            scanf("%d %d", &x, &y);
            f[x] = y;
        }
        scanf("%d", &m);
        printf("Case #%d:\n", t++);
        for(int i=1; i<=m; i++)
        {
            scanf("%s", s);
            if(s[0] == C)
            {
                scanf("%d", &x);
                printf("%d\n", Query(x));
            }
            else
            {
                scanf("%d %d", &x, &y);
                a[x].order = i;//工作的顺序;
                a[x].task = y;
            }
        }
    }
    return 0;
}
View Code

 

Assign the task---hdu3974

原文:http://www.cnblogs.com/zhengguiping--9876/p/4694429.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!