UVA 540 Team Queue
2016-07-16 23:07
357 查看
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"); } }
相关文章推荐
- Codeforces 689D Friends and Subsequences (RMQ+二分)
- StringBuffer、StringBuilder和BigDecimal
- HDU 5288 OO’s Sequence (from: 2015 Multi-University Training Contest 1)
- POJ3080 Blue Jeans
- UITableViewCell高度自适应探索--AutoLayout结合Frame
- LeetCode:Implement Queue using Stacks
- js中document.getElementById("id").value+1问题
- android产品研发(二十一)-->android中的UI优化
- 【一天一道LeetCode】#232. Implement Queue using Stacks
- 【一天一道LeetCode】#232. Implement Queue using Stacks
- JMenuBar,JMenu,JMenuItem的关系
- Build Slic3r on Windows // 如何在Windows上编译Slic3r
- UE4中使用数据表(Data Table)
- require.js的用法
- Thinking in Java之break与continue的使用
- H5 required 改变错误提示oninvalid、oninput、onforminput
- HDU 2062 Subset sequence[排列组合]
- 【BZOJ-1670】Building the Moat护城河的挖掘 Graham扫描法 + 凸包
- VS2008 fatal error LNK1000: Internal error during IncrBuildImage 解决方案
- UE4入门与精通