POJ2259,luoguUVA540-Team Queue【队列】
生活随笔
收集整理的這篇文章主要介紹了
POJ2259,luoguUVA540-Team Queue【队列】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
正題
POJ題目鏈接:http://poj.org/problem?id=2259
luogu評測記錄:https://www.luogu.org/recordnew/lists?uid=52918&pid=UVA540
題目大意
有n個隊伍排隊,新進來一個人時那個人會排在他的隊伍的最后一個人的后面,如果這里沒有他隊伍的人他就只能排在最后面。
有兩個操作,一個是一個人加入,一個是退出隊首
求每次退出退出的人
code
#include<cstdio> #include<queue> #include<cstring> #define TN 1010 using namespace std; queue<int> tq,q[TN]; int k,t,n,x,inq[TN],team[1000010]; char s[11]; int main() {k=0;while('.'=='.'){memset(inq,0,sizeof(inq));k++;scanf("%d",&t);if (!t) break;for(int i=1;i<=t;i++){scanf("%d",&n);for(int j=1;j<=n;j++)scanf("%d",&x),team[x]=i;while(!q[i].empty())q[i].pop();}while(!tq.empty())tq.pop();printf("Scenario #%d\n",k);while(true){scanf("%s",s);if(s[0]=='S') break;else if(s[0]=='E'){scanf("%d",&x);q[team[x]].push(x);if(!inq[team[x]])//該隊第一人tq.push(team[x]);inq[team[x]]++;//加入自己隊列}else{x=tq.front();inq[x]--;//退出if(!inq[x]) tq.pop();//隊伍不在當前隊列里了printf("%d\n",q[x].front());//輸出q[x].pop();}}printf("\n");} }總結
以上是生活随笔為你收集整理的POJ2259,luoguUVA540-Team Queue【队列】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 那个上门修电脑的男人帅哥上门修电脑
- 下一篇: tyvj/joyOI 1305-最大子序