Uva 540.Team Queue

队列问题,思路较为清晰

通过模拟操作可以发现可以先队内排列,然后进行队伍排列

其中个别操作由于vector、map嵌套,可能会发生打错凌乱的情况。

 1 #include <cstdio>
 2 #include <vector>
 3 #include <queue>
 4 #include <map>
 5 #include <algorithm>
 6
 7 using namespace std;
 8
 9 int kase=0;
10
11 class LOVE{
12     private:
13         vector<int> Q;
14         queue<int> Q_team[1005];
15         map<int,int> team;
16
17         void debug(){
18             printf("\n");
19             printf("################\n");
20             for(size_t i=0;i<Q.size();i++)
21                 printf("%d ",Q[i]);
22             printf("\n");
23             for(int i=0;i<1005;i++)
24                 if(!Q_team[i].empty())
25                     printf("%d\n",i);
26             printf("################\n\n");
27         }
28
29     public:
30         bool start(){
31             //Init
32             Q.erase(Q.begin(),Q.end());
33             for(int i=0;i<1005;i++)
34                 while(!Q_team[i].empty())
35                     Q_team[i].pop();
36             team.clear();
37
38             //Input
39             int n;
40             scanf("%d",&n);
41             if(n==0)
42                 return false;
43             printf("Scenario #%d\n",++kase);
44
45             for(int i=0;i<n;i++){
46                 int m;
47                 scanf("%d",&m);
48                 while(m--){
49                     int temp;
50                     scanf("%d",&temp);
51                     team[temp]=i;
52                 }
53             }
54
55             char com[10];
56             while(scanf("%s",com),com[0]!=‘S‘){
57                 if(com[0]==‘E‘){
58                     int temp;
59                     scanf("%d",&temp);
60                     Q_team[team[temp]].push(temp);
61                     if(find(Q.begin(),Q.end(),team[temp])==Q.end()){
62                         Q.push_back(team[temp]);
63                     }
64                 }
65                 if(com[0]==‘D‘){
66                     int t= *Q.begin();
67                     printf("%d\n",Q_team[t].front());
68                     Q_team[t].pop();
69                     if(Q_team[t].empty())
70                         Q.erase(Q.begin());
71                 }
72             }
73             printf("\n");
74             return true;
75         }
76 };
77
78 int main(){
79     //freopen("in.txt","r",stdin);
80     LOVE LIVE;
81     while(LIVE.start());
82     return 0;
83 }
时间: 2024-11-10 10:04:07

Uva 540.Team Queue的相关文章

UVa 540 Team Queue(团队队列)

题意  模拟团队队列的入队和出队 STL应用  用一个队列维护团队编号  再用一个队列数组维护个体 #include <cstdio> #include <cstring> #include <queue> #include <map> using namespace std; const int N = 1000005; int team[N]; int main() { int cas = 0, n, t, a; char cmd[20]; while(

UVA - 540 Team Queue(STL,队列 )

Team Queue Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known,

540 - Team Queue

Team Queue PS:因为该题排版较麻烦,这里给出OJ网址:UVa540 - Team Queue 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队友在排队,那么这个新人会插队到最后一个队友的身后.如果没有任何一个队友排队,则他会排到长队的队尾.输入每个团队中所有队员的编号,要求支持如下3种指令(前两种指令可以穿插进行). ENQUEUEx:编号为x的人进入长队. DEQUEUE:长队的队首出队. STOP:停止模拟. 对于每个DEQUEUE指令,输出出队的人的编号. #incl

【UVa 540】Team Queue

  Team Queue  Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the queue in front of the Mensa is a team

UVA 540(队列)

Description  Team Queue  Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the queue in front of the Mensa

Team Queue

Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 129 Accepted Submission(s): 63   Problem Description Queues and Priority Queues are data structures which are known to most computer scie

Winter-2-STL-G Team Queue 解题报告及测试数据

Time Limit:3000MS     Memory Limit:0KB Description Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the q

HDU 1387 Team Queue

Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1889    Accepted Submission(s): 639 Problem Description Queues and Priority Queues are data structures which are known to most computer

HDU 1387 Team Queue( 单向链表 )

Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1294    Accepted Submission(s): 442 Problem Description Queues and Priority Queues are data structures which are known to most computer