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

    题目链接
    *题意:t个队伍,每个队伍有n个人,两种操作:入队某个元素,出队。输出出队元素。
    入队规则:如果该元素所在的队物在队列中,则插入该队伍最后,如果不存在,则插在所有队伍最后。

    #include<bits/stdc++.h>
    using namespace std ;
    const int N = 1010 ;
    int n ;
    int ca ;
    void solve(){
        queue<int>q[N] , tea;//每一个队的队内队列,队伍队列
        unordered_map<int,int>ma;//标记每一编号在属于哪个队
        for(int i = 1 ; i <= n ; i++){
            int t ; 
            scanf("%d" , &t);
            while(t--){
                int x ;
                scanf("%d" , &x);
                ma[x] = i;
            }
        }
        printf("Scenario #%d
    " , ++ca);
        string str ;
        while(cin >> str && str[0] != 'S'){
            if(str[0] == 'E'){
                int x ;
                scanf("%d" , &x);
                int t = ma[x] ;
                if(q[t].size() == 0){
                    tea.push(t);
                }
                q[t].push(x);
            }else{
                int t = tea.front() ; 
                int x = q[t].front() ; q[t].pop();
                if(q[t].size() == 0){
                    tea.pop();
                }
                cout << x << endl;
            }
        }
        puts("");
    }
    
    int main(){
        while(~scanf("%d" , &n) && n){
            solve();
        }
    }
    
    
  • 相关阅读:
    Linux常用命令
    ServerSocketChannel和SocketChannel
    Java扫描包
    [BZOJ3874/AHOI2014]宅男计划
    [BZOJ4029/HEOI2015]定价
    [考试]20151012贪心
    [BZOJ4027/HEOI2015]兔子与樱花
    [考试]20151010
    [考试]20151009
    Test of String
  • 原文地址:https://www.cnblogs.com/nonames/p/12652323.html
Copyright © 2011-2022 走看看