poj 2259——Team Queue
来源:互联网 发布:淘宝人生新笔趣阁 编辑:程序博客网 时间:2024/06/05 05:41
题意:维护一个team queue,每次入队列,如果跟这个元素在一个队里的元素已经在tq中,那么这个元素可以插队。给出t个队以及这些队里面包含的元素,要求出tq的时候的元素。
思路:按照题目输入的顺序,给队编号。因为属于同一个队的可以插队,所以在队列中,同一个队的必然在一起。所以一个总的队列,只用记录下来队伍的编号就可以了,再记录下来每个队伍中的顺序。
从1到n.每次输入的元素用belong数组记录下属于哪个队伍,用数组in表示一个队里面是否有元素在排队。队列q记录目前在tq中队伍的顺序,队列team[i]记录第i个队伍中的顺序。
代码如下:
#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<vector>using namespace std;int belong[1000005];queue<int> team[1005];bool in[1005];queue<int> q;int main(){ // freopen("data.txt","r",stdin); int t; int kase=0; while(scanf("%d",&t)) { if(t==0)break; memset(in,false,sizeof(in)); while(!q.empty())q.pop(); for(int i=0;i<=1000;++i) { while(!team[i].empty())team[i].pop(); } printf("Scenario #%d\n",++kase); for(int i=0;i<t;++i) { int n; scanf("%d",&n); for(int j=0;j<n;++j) { int tmp; scanf("%d",&tmp); belong[tmp]=i; } } char o[10]; while(1) { scanf("%s",o); // cout<<o[0]<<endl; if(o[0]=='E') { int tmp; scanf("%d",&tmp); int b=belong[tmp]; team[b].push(tmp); if(!in[b]){q.push(b);in[b]=1;} } else if(o[0]=='D') { int b=q.front(); int tmp=team[b].front(); team[b].pop(); printf("%d\n",tmp); if(team[b].empty()) { q.pop(); in[b]=0; } } else{ break; } } puts(""); }}
0 0
- poj 2259——Team Queue
- Team Queue(poj 2259)
- POJ 2259 Team Queue
- POJ 2259 Team Queue
- POJ 2259 --- Team Queue
- POJ 2259Team Queue
- POJ 2259 Team Queue
- POJ 2259 Team Queue
- POJ 2259 Team Queue
- POJ 2259 Team Queue(队列)
- ZOJ 1948 POJ 2259 Team Queue
- [HOJ]1456、[POJ]2259:Team queue
- POJ 2259 Team Queue 数据结构 队列
- POJ 2259 Team Queue(队列模拟)
- ACM篇:POJ--2259 Team Queue
- POJ 2259 Team Queue【模拟队列】
- poj-2259-Team Queue【优先队列】
- poj 2259 Team Queue (模拟)
- 考勤管理软件对企业管理非常重要
- Unity3D中c#集合的应用
- 为什么要使用内部类?
- java-JSON net.sf.json使用
- tomcat——配置虚拟目录
- poj 2259——Team Queue
- 开源顺顺表格excel电子表格控件免费下载
- mosquitto集群配置
- 9.19
- iOS7 新Storyboard的使用(一)
- html 文字不换会,显示省略号
- SharePoint 2013 Distributed Cache Service错误和解决办法
- Service
- 【C/S通信交互之Http篇】Cocos2dx(Client)使用Curl与Jetty(Server)实现手机网游Http通信框架(内含解决curl.h头文件找不到问题)