zoukankan      html  css  js  c++  java
  • Uva 540.Team Queue

    队列问题,思路较为清晰

    通过模拟操作可以发现可以先队内排列,然后进行队伍排列

    其中个别操作由于vector、map嵌套,可能会发生打错凌乱的情况。

     1 #include <cstdio>
     2 #include <vector>
     3 #include <queue>
     4 #include <map>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 
     9 int kase=0;
    10 
    11 class LOVE{
    12     private:
    13         vector<int> Q;
    14         queue<int> Q_team[1005];
    15         map<int,int> team;
    16 
    17         void debug(){
    18             printf("
    ");
    19             printf("################
    ");
    20             for(size_t i=0;i<Q.size();i++)
    21                 printf("%d ",Q[i]);
    22             printf("
    ");
    23             for(int i=0;i<1005;i++)
    24                 if(!Q_team[i].empty())
    25                     printf("%d
    ",i);
    26             printf("################
    
    ");
    27         }
    28 
    29     public:
    30         bool start(){
    31             //Init
    32             Q.erase(Q.begin(),Q.end());
    33             for(int i=0;i<1005;i++)
    34                 while(!Q_team[i].empty())
    35                     Q_team[i].pop();
    36             team.clear();
    37 
    38             //Input
    39             int n;
    40             scanf("%d",&n);
    41             if(n==0)
    42                 return false;
    43             printf("Scenario #%d
    ",++kase);
    44 
    45             for(int i=0;i<n;i++){
    46                 int m;
    47                 scanf("%d",&m);
    48                 while(m--){
    49                     int temp;
    50                     scanf("%d",&temp);
    51                     team[temp]=i;
    52                 }
    53             }
    54 
    55             char com[10];
    56             while(scanf("%s",com),com[0]!='S'){
    57                 if(com[0]=='E'){
    58                     int temp;
    59                     scanf("%d",&temp);
    60                     Q_team[team[temp]].push(temp);
    61                     if(find(Q.begin(),Q.end(),team[temp])==Q.end()){
    62                         Q.push_back(team[temp]);
    63                     }
    64                 }
    65                 if(com[0]=='D'){
    66                     int t= *Q.begin();
    67                     printf("%d
    ",Q_team[t].front());
    68                     Q_team[t].pop();
    69                     if(Q_team[t].empty())
    70                         Q.erase(Q.begin());
    71                 }
    72             }
    73             printf("
    ");
    74             return true;
    75         }
    76 };
    77 
    78 int main(){
    79     //freopen("in.txt","r",stdin);
    80     LOVE LIVE;
    81     while(LIVE.start());
    82     return 0;
    83 }
  • 相关阅读:
    HDU2586 How far away?(tarjan的LCA)
    You Raise Me Up
    POJ2891 Strange Way to Express Integers(中国剩余定理)
    POJ2142 The Balance(扩展欧几里得)
    HDU 1166模仿大牛写的线段树
    NetWord Dinic
    HDU 1754 线段树裸题
    hdu1394 Minimum Inversion Number
    hdu2795 Billboard
    【完全版】线段树
  • 原文地址:https://www.cnblogs.com/ohyee/p/5199312.html
Copyright © 2011-2022 走看看