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("
    ");
            
        }
    } 
  • 相关阅读:
    gocurd案例
    Go module的介绍及使用
    shell脚本第二天
    shell脚本第一天
    php实现图片压缩
    Golang协程详解和应用
    layui的表格渲染方式
    layui-treetable使用
    模拟tp5.1加载自定义类
    多卡训练的state_dict
  • 原文地址:https://www.cnblogs.com/hellosnow/p/6387216.html
Copyright © 2011-2022 走看看