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

这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数组开到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. Spring Boot 所提供的配置优先级顺序

    按照优先级从高到低的顺序,具体的列表如下所示. 命令行参数. 通过 System.getProperties() 获取的 Java 系统参数. 操作系统环境变量. 从 java:comp/env 得到 ...

  2. poj 1247 The Perfect Stall 裸的二分匹配,但可以用最大流来水一下

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16396   Accepted: 750 ...

  3. Codeforces 707 E. Garlands (二维树状数组)

    题目链接:http://codeforces.com/problemset/problem/707/E 给你nxm的网格,有k条链,每条链上有len个节点,每个节点有一个值. 有q个操作,操作ask问 ...

  4. 更有效率的使用Visual Studio(一)

    很多比较通用的快捷键的默认设置其实是有一些缩写在里面的,这个估计也是MS帮助我们记忆.比如说注释代码的快捷键是Ctrl + E + C,我们如果知道它是 Ctrl + Edit + Comment C ...

  5. JQery icheck 插件

    <script type="text/javascript"> $(document).ready(function(){ var callbacks_list = $ ...

  6. vector中的erase方法[转+补充]

    注释如下: iterator erase(iterator it);       // 删除指定元素,并返回删除元素后一个元素的位置(如果无元素,返回end())iterator erase(iter ...

  7. php 内置http服务器

    PHP从5.4.0起,内置了一个http服务器,开发人员可以借助这个内置服务器来做一些本地测试. 启动服务器: 打开终端,进入php安装目录,然后执行 php -S localhost: 这样就可以开 ...

  8. 集成iscroll 下拉加载更多 jquery插件

    一个插件总是经过了数月的沉淀,不断的改进而成的.最初只是为了做个向下滚动,自动加载的插件.随着需求和功能的改进,才有了今天的这个稍算完整的插件. 一.插件主功能: 1.下拉加载 2.页面滚动到底部自动 ...

  9. How to log in to Amazon EC2 using PEM format from SecureCRT

    SecureCRT requires both a private and a public key. Use the supplied key.pem file from EC2 here as y ...

  10. 【转】Android 属性动画(Property Animation) 完全解析 (上)

    http://blog.csdn.net/lmj623565791/article/details/38067475 1.概述 Android提供了几种动画类型:View Animation .Dra ...