Gym 100917H之模拟+STL

题目传送门:
http://vjudge.net/problem/Gym-100917H

题意:
有一个office,office下有很多department(部门),现在要我们求office的头儿和部门的头儿是谁,规则如下:
在部门里,年老的为首领,如果年龄一样,则按照这个部门中id最小的那个为首领。
在office中也是如此,年老的为首领,如果年龄一样,则按照这个office中所有部门id最小的那个部门的首领为首领,如果相同,则按照office中所有人id最小的为首领。

用几个map和一个set模拟一下。。
详见代码。。

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

struct person
{
    char name[16];
    int age;
    int depid;//部门id
    int id;//本身id
    bool operator<(const person &oth) const
    {
        if(age!=oth.age)
            return age<oth.age;//年龄优先
        if(depid!=oth.depid)
            return depid<oth.depid;//部门id为次
        return id<oth.id;//个人id最后
    }
};
map<int,int>maid;
map<int,set<person>> ma;//储存部门的首领
set<person> se;//储存office的人
map<pair<int,int>,person> remap;//映射部门里面人的id
int main ()
{
    int t;
    person p;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int type;
        scanf("%d",&type);
        if(type==1)
        {
            scanf("%d",&p.depid);//输入部门id
            scanf("%s",p.name);
            int y,m,d;
            scanf("%d:%d:%d",&d,&m,&y);
            p.age=y*10000+m*100+d;
            if(ma.find(p.depid)==ma.end())
            {
                ma[p.depid]=set<person>();
            }
            p.id=++maid[p.depid];//这个部门的人数+1则为该人的id
            remap[make_pair(p.depid,p.id)]=p;
            ma[p.depid].insert(p);
            se.insert(p);
            printf("%s %s\n",se.begin()->name,ma[p.depid].begin()->name);
        }
        else
        {
            scanf("%d%d",&p.depid,&p.id);
            p=remap[make_pair(p.depid,p.id)];
            ma[p.depid].erase(p);
            se.erase(p);
            printf("%s %s\n",se.empty()?"Vacant":se.begin()->name,ma[p.depid].empty()?"Vacant":ma[p.depid].begin()->name);
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值