题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间。

这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数组开到maxn*maxn。另外当所要打印的文件优先级不是最高的时候也需要排列到后面。

0.016s。

代码:

#include <cstdio>
const int maxn = 101;
int t, n, m, time;
int q[maxn*maxn]; int print() {
int front = 0, rear = n;
while (1) {
int max = q[front];
for (int i = front; i < rear; i++)
if (q[i] > max)
{
if (front == m)
m = rear;
q[rear++] = q[front++];
break;
}
else if (i == rear - 1)
{
time++;
// printf("%d %d\n", time, q[front]);
if (front == m)
return time;
front++;
}
}//while
} int main() {
scanf("%d", &t);
while (t--) {
time = 0;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d", &q[i]);
printf("%d\n", print());
}//while }

这里是水水题的水果君,转载请注明出处。

uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列的更多相关文章

  1. UVa 12100 Printer Queue(queue或者vector模拟队列)

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...

  2. uva 12100 Printer Queue

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...

  3. UVa 12100 Printer Queue (习题 5-7)

    传送门:https://uva.onlinejudge.org/external/121/12100.pdf 题意:队列中待打印的任务(1 <= n <= 100)带有优先级(1-9), ...

  4. 12100 Printer Queue(优先队列)

    12100 Printer Queue12 The only printer in the computer science students’ union is experiencing an ex ...

  5. 【UVA】12100 Printer Queue(STL队列&优先队列)

    题目 题目     分析 练习STL     代码 #include <bits/stdc++.h> using namespace std; int main() { int t; sc ...

  6. 数据结构算法学习之队列(数组模拟java实现)

    数组模拟队列 数组模拟队列 今天学习数组模拟队列.队列常用于生活中的方方面面.比如银行叫号排队.实际上就是队列.所有人抽号排队.先去的先抽号.所以靠前的号最后会先被叫到然后出队.后边的会随之往前移位. ...

  7. 剑指Offer——网易校招内推笔试题+模拟题知识点总结

    剑指Offer--网易校招内推笔试题+模拟题知识点总结 前言 2016.8.2 19:00网易校招内推笔试开始进行.前天晚上利用大约1小时时间完成了测评(这个必须做,关切到你能否参与面试).上午利用2 ...

  8. UVA 540 Team Queue(模拟+队列)

    题目代号:UVA 540 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page ...

  9. Printer Queue UVA - 12100

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...

随机推荐

  1. HDU 5702 Solving Order (水题,排序)

    题意:给定几种不同的颜色和它的权值,按它的权值排序. 析:排序. 代码如下: #include <cstdio> #include <string> #include < ...

  2. android 照相或从相册获取图片并裁剪

    照相或从相册获取图片并裁剪 在android应用中很多时候都要获取图片(例如获取用户的头像)就需要从用户手机上获取图片.可以直接照,也可以从用户SD卡上获取图片,但获取到的图片未必能达到要求.所以要对 ...

  3. Emit Mapper官方文档

    概述 优点 快速指导 类型转换 用户配置

  4. 数据对象ajax学习篇9

    题记:写这篇博客要主是加深自己对数据对象的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢. 对ajax工作道理: 下面这段是来自一个网友的blog: Ajax的道理简单来说通过Xml ...

  5. Java学习笔记之接口

    一.接口的概念与定义 首先考虑一个简单的接口的定义: public interface Output { int MAX_LINE = 40; void out(); void getData(Str ...

  6. 4.3、Libgdx启动类和配置

    (原文:http://www.libgdx.cn/topic/45/4-3-libgdx%E5%90%AF%E5%8A%A8%E7%B1%BB%E4%B8%8E%E9%85%8D%E7%BD%AE) ...

  7. 如何用C#语言构造蜘蛛程序

    "蜘蛛"(Spider)是Internet上一种很有用的程序,搜索引擎利用蜘蛛程序将Web页面收集到数据库,企业利用蜘蛛程序监视竞争对手的网站并跟踪变动,个人用户用蜘蛛程序下载We ...

  8. linux C 9*9

    #include<stdio.h> #include<conio.h> #include <windows.h> void Gotoxy(int x, int y) ...

  9. 【MongoDB】mongoimport and mongoexport of data (一)

    In the software development, we usually are faced with a common question of exporting or importing d ...

  10. OutputDebugString()

    坚定的 Win32 开发者可能对 OutputDebugString() API 函数比較熟悉,它能够使你的程序和调试器进行交谈.它要比创建日志文件easy,并且全部“真正的”调试器都能使用它.应用程 ...