UVA540Team Queue
来源:互联网 发布:sql server distinct 编辑:程序博客网 时间:2024/06/11 14:13
UVA-540
题意:先告诉你有t个团队,每个团队中的每一个人有一个编号。然后空的广场上x来了,如果x所在团队已经在了,那么x排到他的团队队列的最后一个,否则他就作为他那个团队的第一个排在大队列的最后一个。DEQUEUE 时就把排在大队列第一个团队队列的第一个出队并输出来。当第一个队列空了就从第二个上找,以此类推。
解题思路:一开始以为是给的团队的人都在了,改了半天,后面才发现只是告诉我们谁谁谁属于哪个团队,一开始都是没人的。按照它所说的去模拟就形了。
/************************************************************************* > File Name: UVA-540.cpp > Author: Narsh > > Created Time: 2016年07月16日 星期六 15时09分24秒 ************************************************************************/#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <queue>using namespace std;queue<int> team[1010];queue<int> que;int xt[1203000],t,n,a;int main () { int num=0; while (scanf("%d",&n) && n) { num++; printf("Scenario #%d\n",num); while (!que.empty()) que.pop(); memset(xt,0,sizeof(xt)); for (int i = 1; i <= n; i++){ scanf("%d",&t); while (!team[i].empty()) team[i].pop(); for (int j = 1; j <= t; j++) { scanf("%d",&a); xt[a] = i; } } int k; string s; cin>>s; while (s[0] != 'S') { if (s[0] == 'E') { scanf("%d\n",&a); k=xt[a]; if (team[k].empty()) que.push(k); team[k].push(a); } if (s[0] == 'D') { k=que.front(); printf("%d\n",team[k].front()); team[k].pop(); if (team[k].empty()) que.pop(); } cin>>s; } printf("\n"); }}
0 0
- UVA540Team Queue
- UVA540Team Queue(队列)
- Queue
- queue
- Queue
- QUEUE ~
- queue
- queue
- queue
- queue
- queue
- queue
- Queue
- Queue
- queue
- queue
- Queue
- Queue
- <第一行代码>笔记三
- css翻页效果
- HDU 2476 String painter (区间DP)
- Git与SourceTree使用详细指南
- 最大熵模的理解与最大熵模型逻辑回归相似转换条件
- UVA540Team Queue
- Tensorflow让神经网络自动创造音乐
- java i/o流(5) 字节流、字符流的操作
- HTML
- linux内核模块替换系统调用
- SVM支持向量机学习笔记 _ 1 数学基础
- Leetcode题解 168. Excel Sheet Column Title
- Protobuf简单例子
- HDU 4745 Two Rabbits (区间DP)