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--)
    {
        scanf("%d%d", &n, &p);
        for(i = 0; i < n; ++i) scanf("%d", &q[i]);
        cnt = front = 0, rear = n;
        while(front <= p)
        {
            for(i = front + 1; i < rear; ++i)
                if(q[i] > q[front]) break;
            if(i < rear)
            {
                if(front == p) p = rear;
                q[rear++] = q[front];
            }
            else ++cnt;
            ++front;
        }
        printf("%d\n", cnt);
    }
    return 0;
}
时间: 2024-08-08 13:07:18

UVa 12110 Printer Queue(特殊队列)的相关文章

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

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)

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 (习题 5-7)

传送门:https://uva.onlinejudge.org/external/121/12100.pdf 题意:队列中待打印的任务(1 <= n <= 100)带有优先级(1-9), 打印步骤为每次从队首拿出一个, 如果队列中没有优先级比该任务高的, 打印这个任务; 若有优先级高的, 把这个任务放到队尾,  并打印优先级最高的. 每打印一次耗时1分钟, 求给定任务什么时候打印. 水题A半天    不愧是弱渣.......... 最坏的情况需要maxn*maxn的空间........ fro

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

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

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

STL --&gt; queue单向队列

queue单向队列 queue 模板类的定义在<queue>头文件中.与stack 模板类很相似,queue 模板类也需要两个模板参数,一个是元素类型,一个容器类型,元素类型是必要的,容器类型是可选的,默认为deque 类型. 定义queue 对象的示例代码如下:queue<int> q1;queue<double> q2; queue 的基本操作有: q.push(x)                入队,将x 接到队列的末端.q.pop()