日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

queue POJ 2259 Team Queue

發布時間:2024/9/20 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 queue POJ 2259 Team Queue 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

題目傳送門

題意:先給出一些小組成員,然后開始排隊。若前面的人中有相同小組的人的話,直接插隊排在同小組的最后一個,否則只能排在最后面。現在有排隊和出隊的操作。

分析:這題關鍵是將隊列按照組數分組,用另外一個隊列保存組的序號,當該組里沒有人了才換下一組。很好的一道題。

收獲:隊列的靈活運用

?

代碼:

/************************************************ * Author :Running_Time * Created Time :2015/9/9 星期三 14:37:14 * File Name :M.cpp************************************************/#include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std;#define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e3 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; queue<int> id; queue<int> num[N]; map<int, int> mp; bool inq[N]; char op[11]; int n;void init(void) {while (!id.empty ()) id.pop ();for (int i=1; i<=n; ++i) {while (!num[i].empty ()) num[i].pop ();}memset (inq, false, sizeof (inq));mp.clear (); }int main(void) {int cas = 0;while (scanf ("%d", &n) == 1) {if (!n) break;init ();if (cas) puts ("");printf ("Scenario #%d\n", ++cas);int x;for (int i=1; i<=n; ++i) {int m; scanf ("%d", &m);for (int j=1; j<=m; ++j) {scanf ("%d", &x);mp[x] = i;}}scanf ("%s", &op);while (strcmp (op, "STOP")) {if (strcmp (op, "ENQUEUE") == 0) {scanf ("%d", &x);if (!inq[mp[x]]) {inq[mp[x]] = true;id.push (mp[x]);}num[mp[x]].push (x);}else {if (id.empty ()) continue;int fir = id.front ();printf ("%d\n", num[fir].front ()); num[fir].pop ();if (num[fir].empty ()) {inq[fir] = false; id.pop ();}}scanf ("%s", &op);}}return 0; }

  

轉載于:https://www.cnblogs.com/Running-Time/p/4795710.html

總結

以上是生活随笔為你收集整理的queue POJ 2259 Team Queue的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。