uva 540 Team Queue(queue与STL其他容器的综合运用)
2016-09-28 16:19
423 查看
题目链接:here
思路还是很简单的,,用map[a][i] 表示编号为a 的人在i的队伍里面,然后用队列表示每个队伍;
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<string>
#include<cstdio>
using namespace std;
const int maxn = 1000+10;
int main(){
int t;
int x=1;
//freopen("0.txt","r",stdin);
while(~scanf("%d",&t)&&t)
{
printf("Scenario #%d\n",x++);
map<int,int> team;
for(int i=1;i<=t;i++){
int n;
scanf("%d",&n);
while(n--){
int a;
scanf("%d",&a);
team[a]=i;
}
}
queue<int> q,q2[maxn];
string s;
while(cin>>s)
{
if(s[0]=='S') break;
else if(s[0]=='E'){
int a;
scanf("%d",&a);
int t=team[a];
if(q2[t].empty()) q.push(t);
q2[t].push(a);
}else if(s[0]=='D'){
int t=q.front();
cout<<q2[t].front()<<endl;;
q2[t].pop();
if(q2[t].empty()) q.pop();
}
}
printf("\n");
}
return 0;
}
思路还是很简单的,,用map[a][i] 表示编号为a 的人在i的队伍里面,然后用队列表示每个队伍;
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<string>
#include<cstdio>
using namespace std;
const int maxn = 1000+10;
int main(){
int t;
int x=1;
//freopen("0.txt","r",stdin);
while(~scanf("%d",&t)&&t)
{
printf("Scenario #%d\n",x++);
map<int,int> team;
for(int i=1;i<=t;i++){
int n;
scanf("%d",&n);
while(n--){
int a;
scanf("%d",&a);
team[a]=i;
}
}
queue<int> q,q2[maxn];
string s;
while(cin>>s)
{
if(s[0]=='S') break;
else if(s[0]=='E'){
int a;
scanf("%d",&a);
int t=team[a];
if(q2[t].empty()) q.push(t);
q2[t].push(a);
}else if(s[0]=='D'){
int t=q.front();
cout<<q2[t].front()<<endl;;
q2[t].pop();
if(q2[t].empty()) q.pop();
}
}
printf("\n");
}
return 0;
}
相关文章推荐
- 5_6 团体队列(UVa540)<queue与STL其他容器的综合运用>
- 5_5 集合栈计算机(UVa12096)<stack与STL其他容器的综合运用>
- UVa 540 Team Queue (STL list&queue模拟插队)
- UVA - 540 Team Queue(STL,队列 )
- UVa 540 Team Queue 【STL】【queue】
- UVa 540 Team Queue 【STL】
- #UVA 540 Team Queue (STL map+queue)
- UVa 540 STL之queue的运用
- UVa - 540 - Team Queue(STL - 队列queue)
- UVa 540 Team Queue
- UVa540 Team Queue
- UVa540 Team Queue (queue)
- UVa 540 - Team Queue 数据结构专题
- UVA540 TeamQueue
- uva540 Team Queue by sixleaves
- uva 540 Team Queue
- uva 540 Team Queue
- uva 540 - Team Queue
- UVA 540-Team Queue
- UVA 540 Team Queue(团体队列)