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模拟一下。。
详见代码。。
代码:
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; }
相关文章推荐
- UVaLive 6581 && Gym 100299B What does the fox say? (模拟+STL)
- Gym 100917H Hierarchy 【STL好题】
- POJ 1208 The Blocks Problem 栈模拟 练STL
- STL中list的使用及模拟实现
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
- Gym-101505D Rotating Display [模拟]
- Gym - 101667B Connect3 [模拟]
- Gym - 100637A Nano alarm-clocks 模拟
- Gym 100959L_String Modification(模拟)
- Gym 100507I Traffic Jam in Flower Town (模拟)
- Gym 100112D Doorman 模拟—水
- Gym - 100917H
- 【STL】迭代器与List的模拟实现
- STL——模拟实现空间配置器
- 【STL】模拟STL中的List轮
- Gym - 100543D Wheels 模拟|BFS|签到
- 模拟实现STL-Vector
- cf 599 C (模拟+STL)
- POJ 字符串的全排列 水题也搞我 多种方法 DFS,STL,直接模拟。。。。。。
- Codeforces Gym 101158 B. Quality of Check Digits (模拟)