zoukankan      html  css  js  c++  java
  • UVa

    题意

    有一个长队包含几个小队, 每个小队连在一起排成一个长队, 有以下三种操作 :

    ① ENQUEUE 在队列中输入元素x
    ② DEQUEUE 输出长队队首并将其从队列中移除
    ③ STOP 结束处理

    如果有队友就站到自己所属队列的最末, 如果没有队友就站到整个长队的最末

    AC代码

    #include <iostream>
    #include <cstdio>
    #include <map>
    #include <queue>
    #include <cstring>
    using namespace std;
    
    const int maxn = 1000 + 10;
    int main()
    {
        int q,x;
        int casenum = 0;
        while( ~scanf("%d",&q) && q )
        {
            printf("Scenario #%d
    ", ++casenum);
            map<int, int> team;
            for( int i = 1; i <= q; i++ )
            {
                int n;
                scanf("%d",&n);
                while( n-- ){
                    scanf("%d",&x);
                    team[x] = i;  //记录编号为x的人所在的队伍为第i队
                    //printf("%d,",team[x]);
                }
            }
            queue<int> q, sq[maxn];
            //q是长队的队列,sq[i]是小队i成员的队列
            for(;;)
            {
                char s[maxn];
                scanf("%s",s);
                int mrk = s[0];
                if( mrk == 'S' )
                {
                    puts("");  //Print a blank line
    after each test case, even after the last one.
                    break;
                }
                else if( mrk == 'E' )
                {
                    scanf("%d", &x);
                    int t = team[x];
                    if(sq[t].empty())
                        q.push(t); //团队t进入队列
                    sq[t].push(x);
                }
                else if( mrk == 'D' )
                {
                    int t = q.front();
                    printf("%d
    ", sq[t].front());
                    sq[t].pop();
                    if(sq[t].empty())
                        q.pop(); //团体t全体出队列
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    mysql 查询技巧
    如何查看mysql索引
    windows下安装redis以及简单的事例
    Buildroot make网卡interfaces文件被修改
    VirtualBox只能生成32位虚拟机
    python-websocket-server hacking
    crontab定时任务
    Linux修改串口irq
    emmc boot_config文件不存在
    /dev/mem直接操作硬件寄存器
  • 原文地址:https://www.cnblogs.com/JinxiSui/p/9740650.html
Copyright © 2011-2022 走看看