• UVA


    /*
      思路:
      队列题,每个团队有一个队列,团队整体又形成一个队列
      
      收获:
      1. 关于 queue
      队列是符合FIFO原则的“公平队列”,STL队列定义在头文件<queue>中
      声明:queue<int> s;
      操作:
      push()和pop()为入队出队操作,front()取队首元素(但不删除)
      
      2. 关于优先队列
      同样定义在<queue>中
      声明:priority_queue<int>pq;
      特点:每次出队的不是先进队列的元素,而是优先级最高的元素
      由于出队的不是先进队的元素,出队的方法尤 front() 变为了 top()
      
      3. 自定义类型也能组成优先队列
      只要定义了“小于”运算符,能比较大小,就可以使用优先队列
      特殊的情况下,需要使用自定义方式比较优先级,具体情况和处理见《入门经典》P119
      
      4. 常见优先队列,STL已提供其定义方法,例如“越小的整数优先级越大的队列”可写成:
         priority_queue<int, vector<int>, greater<int> > pq;
    	 如果时越小整数优先级越低的队列:
    	 priority_queue<int> pq;
    */



    #include <cstdio>
    #include <queue>
    #include <map>
    #include <string>
    #include <iostream>
    using namespace std;
    
    const int maxt = 1010;
    int main()
    {
    	cin.tie(0);
    	cin.sync_with_stdio(false);
    	
    	int t, kase = 0;
    	while (cin >> t && t)
    	{
    		cout << "Scenario #" << ++kase << endl;
    		
    		//记录所有人的团队编号,team[x]的值表示标号为x的人所在的团队编号
    		map<int, int> team;
    		for (int i = 0; i < t; i++) //t为团队数目 
    		{
    			int n, x; //n为每一团队人数
    			cin >> n;
    			while (n--)
    			{
    				cin >> x;
    				team[x] = i;
    			} 
    		} 
    		
    		//模拟
    		queue<int> q, q2[maxt]; //q是团队的队列,q2[i]是团队i的成员的队列
    		while (1)
    		{
    			int x;
    			string cmd;
    			cin >> cmd;
    			if (cmd[0] == 'S') break;
    			if (cmd[0] == 'D')
    			{
    				int t = q.front(); // 先找到队首元素是哪组 
    				cout << q2[t].front() << endl; q2[t].pop(); // 将队首元素pop出他所在的队
    				if (q2[t].empty()) q.pop(); // 若原来队首元素所在的队就只有一人,pop出来后,该队就没人了,该队从团队队列中pop出来
    			}
    			else if (cmd[0] == 'E')
    			{
    				cin >> x;
    				int t = team[x]; //找到他的对应团队
    				if (q2[t].empty()) q.push(t); //如果团队中原来没人排队,则团队先进入团队队列
    				q2[t].push(x); //编号x的人进入自己的团队排队 
    			} 
    		 }
    		 cout << endl;
    	}
    	return 0;
    }


  • 相关阅读:
    python 希尔排序
    python 选择排序
    python 插入排序
    怎么根据返回数量,来渲染点赞星星的个数变高量?
    avalon $computed不起作用?
    移动端点击事件兼容问题,在pc端可以点,在手机上不可以点
    移动端弹出遮罩层禁止页面滚动,遮罩里面的框允许滚动如何实现。
    移动端,如何禁止弹窗下面内容滚动/页面滚动
    avalon数据已更新,视图未更新的bug修复
    Python 导入分部分项前的 数据处理
  • 原文地址:https://www.cnblogs.com/mofushaohua/p/7789463.html
Copyright © 2020-2023  润新知