首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2013-11-01 
(队列的应用5.3.3)POJ 3125 Printer Queue(优先队列的使用)/* * POJ_3125.cpp * *Created on: 2013年10月3

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

/* * 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;}

热点排行