3 条题解

  • 1
    @ 2026-8-3 9:36:31
    #include <bits/stdc++.h>
    using namespace std;
    map<int, int> mp, vis;
    map<int, queue<int> > team;
    queue<int> q, qq;
    int main()
    {
        int t, cnt = 1;
        while (cin >> t)
        {
            mp.clear(); vis.clear(); team.clear();
            q = qq;
            if (t == 0) break;
            cout << "Scenario #" << cnt << "\n";
            for (int i = 1, x; i <= t; i++)
            {
                cin >> x;
                for (int j = 1, y; j <= x; j++)
                {
                    cin >> y;
                    mp[y] = i;
                }
            }
            string op; int x;
            while (cin >> op)
            {
                if (op == "STOP") break;
                if (op == "ENQUEUE")
                {
                    cin >> x;
                    if (vis[mp[x]] == 0) q.push(mp[x]);
                    team[mp[x]].push(x);
                    vis[mp[x]] = 1;
                }
                else
                {
                    cout << team[q.front()].front() << '\n';
                    team[q.front()].pop();
                    if (team[q.front()].size() == 0)
                        vis[q.front()] = 0, q.pop();
                }
            }
            cnt ++;
            cout << "\n";
        }
        return 0;
    }  
    
    • 0
      @ 2026-8-12 10:02:24

      注释一下

      #include<bits/stdc++.h>
      using namespace std;
      deque<int>Q,q[1100];int t,cnt,c[1110000];
      //Q代表每个队伍的排队情况,q是每个队伍中队员的排队情况
      char s[21];
      int main()
      {
          while(scanf("%d",&t)!=EOF&&t)
          {
              printf("Scenario #%d\n",++cnt);
              Q.clear();
              for(int i=1;i<=t;i++)q[i].clear();
              int n,x;
              for(int i=1;i<=t;i++)
              {
                  scanf("%d",&n);
                  for(int j=1;j<=n;j++)scanf("%d",&x),c[x]=i;
      			//c[x]=i代表编号为x的人属于第i个队伍 
              }
              while(scanf("%s",s)!=EOF&&s[0]!='S')
              {
                  if(s[0]=='E')
                  {
                      scanf("%d",&x);
                      if(q[c[x]].empty())Q.push_back(c[x]);
      				//没有队友,不能插队,这个队伍新加入队尾 
                      q[c[x]].push_back(x);
      				//不管前面有没有队友,他现在都是排在这个队伍的最后
                  }
                  else if(s[0]=='D')
                  {
                      x=Q.front();
                      printf("%d\n",q[x].front()),q[x].pop_front();
      				//排在第一的队伍的第一人出列 
                      if(q[x].empty())Q.pop_front();//排在第一的队伍中的人全部出队了 
                  }
              }
          	puts("");
          }
          return 0;
      }
      
      • 0
        @ 2026-7-15 22:08:59
        #include<bits/stdc++.h>
        using namespace std;
        deque<int>Q,q[1100];int c[1110000];
        char s[21];
        int main()
        {
            int t,cnt=0;
            while(scanf("%d",&t)!=EOF&&t!=0)
            {
                printf("Scenario #%d\n",++cnt);
                Q.clear();
                for(int i=1;i<=t;i++)q[i].clear();
                int n,x;
                for(int i=1;i<=t;i++)
                {
                    scanf("%d",&n);
                    for(int j=1;j<=n;j++)scanf("%d",&x),c[x]=i;
                }
                while(scanf("%s",s)!=EOF&&s[0]!='S')
                {
                    if(s[0]=='E')
                    {
                        scanf("%d",&x);
                        if(q[c[x]].empty())Q.push_back(c[x]);
                        q[c[x]].push_back(x);
                    }
                    else if(s[0]=='D')
                    {
                        int x=Q.front();
                        printf("%d\n",q[x].front()),q[x].pop_front();
                        if(q[x].empty())Q.pop_front();
                    }
                }
                printf("\n");
            }
            return 0;
        }
        
        • 1

        *【STL:deque】团体队列 Team Queue

        信息

        ID
        1271
        时间
        2000ms
        内存
        128MiB
        难度
        5
        标签
        递交数
        126
        已通过
        50
        上传者