UVa 12100 Printer Queue (习题 5-7)

传送门:https://uva.onlinejudge.org/external/121/12100.pdf

题意:队列中待打印的任务(1 <= n <= 100)带有优先级(1-9), 打印步骤为每次从队首拿出一个, 如果队列中没有优先级比该任务高的, 打印这个任务; 若有优先级高的, 把这个任务放到队尾,  并打印优先级最高的. 每打印一次耗时1分钟, 求给定任务什么时候打印.

水题A半天    不愧是弱渣..........

最坏的情况需要maxn*maxn的空间........

front  rear  记录前后位置

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3
 4 const int MAXN = 111;
 5 int t, n, m, _time;
 6 int que[MAXN*MAXN];
 7
 8 void process(){
 9     int front = 0, rear = n;
10     while(true){
11         int maxi = que[front];
12         for(int i = front; i < rear; ++i){
13             if(que[i] > maxi){
14                 if(front == m) m = rear;
15                 que[rear++] = que[front++];
16                 break;
17             }
18             else if(i == rear - 1){
19                 ++_time;
20                 if(front == m) return ;
21                 front++;
22             }
23         }
24     }
25 }
26 int main(){
27     cin >> t;
28     while(t--){
29         _time = 0;
30         cin >> n >> m;
31         for(int i = 0; i < n; ++i) cin >> que[i];
32         process();
33         cout << _time << endl;
34     }
35     return 0;
36 }
时间: 2024-10-13 05:51:55

UVa 12100 Printer Queue (习题 5-7)的相关文章

UVa: 12100 - Printer Queue

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3252 题目描述:有一些文件需要打印机打印,每个人物有不同的优先级(1-9),打印机的运作方式为:首先从打印队列里取出一个任务J,如果队列里有比J更急的任务,则直接把任务放到打印队列的尾部,否则打印任务J.输入打印队列中各个任务的优先级以及所关注的任务在队列中的位置(对首位置为0).

UVA 12100 Printer Queue(队列和优先队列,水)

1 //#include<bits/stdc++.h> 2 #include<cstdio> 3 #include<queue> 4 #include<algorithm> 5 using namespace std; 6 typedef long long ll; 7 /** 8 题意:所有任务在队列中,若当前打印的任务优先级不是最大,则移动到队列尾部.问下标为k的任务在什么时刻被打印: 9 思路:用优先队列判断优先级是否最高.用队列模拟任务 10 (1)

12100 Printer Queue(优先队列)

12100 Printer Queue12 The only printer in the computer science students’ union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in the printer queue and you may have to wait for hours to get a single page of output. Bec

UVa 12110 Printer Queue(特殊队列)

题意  模拟打印队列   队列中有优先级大于队首的元素   队首元素就排到队尾  否则队首元素出队  输出开始在p位置的元素是第几个出队的 直接模拟这个过程就行了 #include <bits/stdc++.h> using namespace std; const int N = 205; int q[N]; int main() { int cas, n, p, cnt, front, rear, i; scanf("%d", &cas); while(cas-

Printer Queue

Description The only printer in the computer science students' union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in the printer queue and you may have to wait for hours to get a single page of output. Because some

uva The Dole Queue

题目如下: The Dole Queue  In a serious attempt to downsize (reduce) the dole queue, The NewNational Green Labour Rhinoceros Party has decided on the followingstrategy. Every day all dole applicants will be placed in a largecircle, facing inwards. Someone

poj 3125 Printer Queue (队列)

 Printer Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3679   Accepted: 1975 Description The only printer in the computer science students' union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs i

POJ 3125 Printer Queue 数据结构 队列

Printer Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4329   Accepted: 2269 Description The only printer in the computer science students' union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in t

UVa12100,Printer Queue

水题,1A过的 数据才100,o(n^3)都能过,感觉用优先队列来做挺麻烦的,直接暴力就可以了,模拟的队列,没用stl #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <queue> #define maxn 100+5 using namespace std; int mid[maxn],v[maxn],q[maxn*maxn