UVa
来源:互联网 发布:数据库发展方向 编辑:程序博客网 时间:2024/06/05 02:07
题意
有一个长队包含几个小队, 每个小队连在一起排成一个长队, 有以下三种操作 :
① ENQUEUE 在队列中输入元素x
② DEQUEUE 输出长队队首并将其从队列中移除
③ STOP 结束处理如果有队友就站到自己所属队列的最末, 如果没有队友就站到整个长队的最末
AC代码
#include <iostream>#include <cstdio>#include <map>#include <queue>#include <cstring>using namespace std;const int maxn = 1000 + 10;int main(){ int q,x; int casenum = 0; while( ~scanf("%d",&q) && q ) { printf("Scenario #%d\n", ++casenum); map<int, int> team; for( int i = 1; i <= q; i++ ) { int n; scanf("%d",&n); while( n-- ){ scanf("%d",&x); team[x] = i; //记录编号为x的人所在的队伍为第i队 //printf("%d,",team[x]); } } queue<int> q, sq[maxn]; //q是长队的队列,sq[i]是小队i成员的队列 for(;;) { char s[maxn]; scanf("%s",s); int mrk = s[0]; if( mrk == 'S' ) { puts(""); //Print a blank lineafter each test case, even after the last one. break; } else if( mrk == 'E' ) { scanf("%d", &x); int t = team[x]; if(sq[t].empty()) q.push(t); //团队t进入队列 sq[t].push(x); } else if( mrk == 'D' ) { int t = q.front(); printf("%d\n", sq[t].front()); sq[t].pop(); if(sq[t].empty()) q.pop(); //团体t全体出队列 } } } return 0;}
阅读全文
0 0
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- 开始阅读redis源代码
- 哈尔滨理工大学第七届程序设计竞赛决赛(网络赛-高年级组)B 幸运大奖【DP】
- ubutnu nvidia driver
- 用python将LTE-NB NAS消息转换成wireshark文件格式解析
- 我这样减少了26.5M Java内存!
- UVa
- poj2892(treap)
- IT行业风投
- 2017-12-21 ubuntu first day
- python爬虫爬取goubanjia的代理ip
- 机器学习必知的15大框架
- Android界面编程之ViewSwitcher
- sscanf sprintf stringstream
- lucene&solr从入门到精通-----创建索引,写到索引库