您的位置:首页 > 其它

Gym 100917H之模拟+STL

2016-10-02 00:57 337 查看
题目传送门:

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Gym