zoukankan      html  css  js  c++  java
  • 【POJ 2259】 Team Queue

    【题目链接】

                http://poj.org/problem?id=2259

    【算法】

              由题,一个人入队时,若这个人所在的组已经有人在队列中,则加入队列,否则排到队末

              因此我们发现,这个队列一定是由连续的一组人的若干段组成,不妨用一个队列记录每组人的顺序,再分别将每组建一个队列

              维护这(n+1)个队列即可,具体细节,笔者不再赘述

    【代码】

              

    #include <algorithm>  
    #include <bitset>  
    #include <cctype>  
    #include <cerrno>  
    #include <clocale>  
    #include <cmath>  
    #include <complex>  
    #include <cstdio>  
    #include <cstdlib>  
    #include <cstring>  
    #include <ctime>  
    #include <deque>  
    #include <exception>  
    #include <fstream>  
    #include <functional>  
    #include <limits>  
    #include <list>  
    #include <map>  
    #include <iomanip>  
    #include <ios>  
    #include <iosfwd>  
    #include <iostream>  
    #include <istream>  
    #include <ostream>  
    #include <queue>  
    #include <set>  
    #include <sstream>  
    #include <stdexcept>  
    #include <streambuf>  
    #include <string>  
    #include <utility>  
    #include <vector>  
    #include <cwchar>  
    #include <cwctype>  
    #include <stack>  
    #include <limits.h> 
    using namespace std;
    #define MAXN 1010
    #define MAXS 1000010
    
    int i,n,s,x,pos,TC;
    int g[MAXS];
    bool inq[MAXN];
    char opt[10];
    queue< int > ord;
    queue< int > q[MAXN];
    
    int main() 
    {
            
            while (scanf("%d",&n) != EOF && n)
            {
                    memset(inq,false,sizeof(inq));
                    while (!ord.empty()) ord.pop();
                    for (i = 1; i <= n; i++) 
                    {
                            while (!q[i].empty()) 
                                    q[i].pop();    
                    }
                    for (i = 1; i <= n; i++)
                    {
                            scanf("%d",&s);
                            while (s--)
                            {
                                    scanf("%d",&x);
                                    g[x] = i;
                            }
                    }        
                    printf("Scenario #%d
    ",++TC);
                    while (true)
                    {
                            scanf("%s",&opt);
                            if (opt[0] == 'S') break;
                            if (opt[0] == 'E')
                            {
                                    scanf("%d",&x);
                                    if (inq[g[x]]) q[g[x]].push(x);
                                    else
                                    {
                                            inq[g[x]] = true;
                                            ord.push(g[x]);
                                            q[g[x]].push(x);
                                    }
                            }
                            if (opt[0] == 'D')
                            {
                                    pos = ord.front();
                                    printf("%d
    ",q[pos].front());
                                    q[pos].pop();
                                    if (q[pos].empty()) 
                                    {
                                            ord.pop();
                                            inq[pos] = false;
                                    }
                            }
                    }
                    printf("
    ");
            }
            
            return 0;
        
    }
  • 相关阅读:
    Android控件之ListView探究二
    Android控件之Gallery探究
    Android控件之CheckBox、RadioButton探究
    如何解决虚拟机安装centos无法全屏显示问题!
    在Windows下远程桌面连接Linux XManager篇
    putty 中文乱码解决方法
    在IIS上启用Gzip压缩(HTTP压缩)
    LINUX下RPM的使用方法
    虚拟机和主机之间文本的复制和粘贴
    windows上透过Xmanager连接Centos的远程桌面
  • 原文地址:https://www.cnblogs.com/evenbao/p/9245664.html
Copyright © 2011-2022 走看看