zoukankan      html  css  js  c++  java
  • UVa 540 Team Queue 【STL】

    题意:给出t个团体,这t个团体排在一起,每次新来一个x排队,如果在整个的团体队列中,有x的队友,那么x排在它的队友的后面,如果他没有队友,则排在长队的队尾

    求给出的每一个出队命令,输出出队的人的编号

    紫书上的思路:有两个队列,一个是每一个团体内部形成的队列,还有一个是这t个团体又构成的队列

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<queue> 
     9 #include<algorithm>  
    10 #define mod=1e9+7;
    11 using namespace std;
    12 
    13 typedef long long LL;
    14 const int maxn=10005;
    15 
    16 int main(){
    17     int t,kase=0;
    18     while(scanf("%d",&t)==1&&t){
    19         printf("Scenario #%d
    ",++kase);
    20         
    21         map<int,int> team;
    22         for(int i=0;i<t;i++){
    23             int n,x;
    24             scanf("%d",&n);
    25             while(n--){
    26                 scanf("%d",&x);
    27                 team[x]=i;
    28             }
    29         }
    30         
    31         queue<int> q,q2[maxn];
    32         for(;;){
    33             int x;
    34             char cmd[10];
    35             scanf("%s",cmd);
    36             if(cmd[0]=='S') break;
    37             else if(cmd[0]=='D'){
    38                 int t=q.front();
    39                 printf("%d
    ",q2[t].front());q2[t].pop();
    40                 if(q2[t].empty()) q.pop();//如果团体t全部为空,则将团体t整个从团体队列中出去 
    41             }
    42             else if(cmd[0]=='E'){
    43                 scanf("%d",&x);
    44                 int t=team[x];
    45                 if(q2[t].empty()) q.push(t);//如果团体t现在为空,将它加入团体队列中 。对应于x来的时候,没有一个队友,则他排到长队的队尾 
    46                 q2[t].push(x);//将编号为x的人加入它应该在的小团队中 
    47             }
    48         }
    49         printf("
    ");
    50     }
    51     return 0;
    52 }
    View Code
  • 相关阅读:
    阿里云OSS对象存储 简单上传文件
    [转]eclipse查看某个java类属于哪个jar包
    win7自带照片查看器
    代码规范,李师兄的指导
    Python 结巴分词模块
    Python requests模块
    CTF
    Python requests模块在Windows下安装
    CentOS 6.5部署HTTP WEB服务器和FTP服务器
    Django搭建博客后台
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4358186.html
Copyright © 2011-2022 走看看