(队列的应用5.3.3)POJ 3125 Printer Queue(优先队列的使用)

来源:互联网 发布:linux修改文件用户权限 编辑:程序博客网 时间:2024/05/17 09:37
/* * POJ_3125.cpp * *  Created on: 2013年10月31日 *      Author: Administrator */#include <iostream>#include <cstdio>#include <queue>using namespace std;int main() {int t;scanf("%d", &t);while (t--) {queue<int> q;priority_queue<int> v;int n, m;scanf("%d%d", &n, &m);int i;for (i = 0; i < n; ++i) {int a;scanf("%d", &a);q.push(a);v.push(a);}while (true) {int x = q.front();q.pop();if (m == 0) {//如果m==0,则证明现在打印的是目标任务if (x != v.top()) {//如果队列中还有优先级比x高的..m = v.size() - 1;//下标是从0开始的q.push(x);//将该任务放到队尾} else {break;}} else {//如果现在的任务还不是目标任务--m;if (x != v.top()) {q.push(x);} else {v.pop();}}}printf("%d\n", n - q.size());}return 0;}