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;
        
    }
  • 相关阅读:
    POJ 2996 Help Me with the Game (模拟)
    PCL系列——怎样逐渐地配准一对点云
    sublime text3同时编辑多行
    博客搬家
    将博客搬至CSDN
    centos7用xshell可以连接, xftp连接失败!(墙裂推荐)
    重启ssh服务出现Redirecting to /bin/systemctl restart sshd.service
    重装wordpress
    ubuntu 16.04 启用root用户方法
    Ubuntu创建新用户并增加管理员权限(授权有问题)
  • 原文地址:https://www.cnblogs.com/evenbao/p/9245664.html
Copyright © 2011-2022 走看看