码迷,mamicode.com
首页 > 其他好文 > 详细

Uva 540.Team Queue

时间:2016-02-18 21:37:25      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:

队列问题,思路较为清晰

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

 

其中个别操作由于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 }

 

Uva 540.Team Queue

标签:

原文地址:http://www.cnblogs.com/ohyee/p/5199312.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!