题目大意:n条队伍,然后开始组成一条长队,如果长队中已经有自己人,直接插队插到自己人最后面,如果没有乖乖排最后。
题目思路:使用map容器记录每个人对应的队伍,然后插入的时候判断队里有没有自己人,如果没有的话就把对应的队伍号放到长队q的最后面,输出的时候先看长队q.front()对应的那个队伍还有没有人,没人的话就让下一个队伍输出
以下是代码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<map> #include<queue> using namespace std; int main(){ int n,a,b,num=0; string cmd; while(~scanf("%d",&n)&&n){ printf("Scenario #%dn",++num); map<int,int>team; queue<int>q,q2[1005]; for(int i=0;i<n;i++){ scanf("%d",&a); for(int j=0;j<a;j++){ scanf("%d",&b); team[b]=i; } } while(cin>>cmd){ if(cmd[0]=='S'){ break; } else if(cmd[0]=='E'){ int temp,t; scanf("%d",&temp); t=team[temp]; if(q2[t].empty()){ q.push(t); } q2[t].push(temp); } else if(cmd[0]=='D'){ int t=q.front(); while(q2[t].empty()){ q.pop(); t=q.front(); } printf("%dn",q2[t].front()); q2[t].pop(); } } printf("n"); } }
最后
以上就是孝顺唇膏最近收集整理的关于UVA 540 (队列与map容器)的全部内容,更多相关UVA内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复