zoukankan      html  css  js  c++  java
  • UVa540 Team Queue(队列queue)

    队列

    STL队列定义在头文件<queue>中,

    用“ queue<int>s ” 方式定义,

    用push()和pop()进行元素的入队和出队操作,

    front()取队首元素(但不删除)。

    #include<cstdio>
    #include<queue>
    #include<map>
    using namespace std;
    
    const int maxt=1000+10;
    
    int main(){
        int t,kase=0;
        while(scanf("%d",&t)==1&&t){
            printf("Scenario #%d
    ",++kase);
            //记录所有人的团队编号 
            map<int,int> team;//team[x]表示编号为X的人所在的团队编号 
            for(int i=0;i<t;i++){
                int n,x;
                scanf("%d",&n);
                while(n--){
                    scanf("%d",&x);
                    team[x]=i;
                }
            }
            //模拟 
            queue<int> q,q2[maxt];//q是团队的队列,而q2[i]是团队i成员的队列 
            while(1){
                int x;
                char cmd[10];
                scanf("%s",cmd);
                if(cmd[0]=='S') break;
                else if(cmd[0]=='D'){
                    int t=q.front();
                    printf("%d
    ",q2[t].front());
                    q2[t].pop();
                    if(q2[t].empty())
                        q.pop();//团体t全体出队列 
                }
                else if(cmd[0]=='E'){
                    scanf("%d",&x);
                    int t=team[x];
                    if(q2[t].empty()) q.push(t);//团体t进入队列
                    q2.push(x);
                }
            }
            printf("
    ");
            
        }
    } 
  • 相关阅读:
    5285: [Hnoi2018]寻宝游戏
    CF 1117 E. Decypher the String
    4515: [Sdoi2016]游戏
    CF 1051 G. Distinctification
    4820: [Sdoi2017]硬币游戏
    HNOI2019游记
    最近公共祖先(LCT)
    [WC2006]水管局长(LCT)
    P4178 Tree(点分治)
    二维凸包
  • 原文地址:https://www.cnblogs.com/hellosnow/p/6387216.html
Copyright © 2011-2022 走看看