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

这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数组开到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. 如何防止ASP.NET网站遭受CSRF的攻击

    转载地址: http://www.cnblogs.com/shanyou/p/5038794.html?hmsr=toutiao.io&utm_medium=toutiao.io&ut ...

  2. HDU 5534 Partial Tree (完全背包变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5534 题意: 给你度为1 ~ n - 1节点的权值,让你构造一棵树,使其权值和最大. 思路: 一棵树上 ...

  3. iOS维码的生成和扫描

    iOS生成二维码(彩色 + 阴影) http://www.jianshu.com/p/85e131155b79?plg_nld=1&plg_uin=1&plg_auth=1&p ...

  4. xiaocms 关于搜索功能 添加搜索字段

    自己折磨了好几天 就是没研究个出像样的的东西 看了一下 core/controller/index.php searchAction()方法 但是不知从何下手.查了sql语句,还是没实现 请教了一位自 ...

  5. OC:习题来自平时搜索

    == 第一部分 ==  类变量的@protected ,@private,@public,@package,声明各有什么含义?写一个标准宏MIN,这个宏输入两个参数并返回较小的一个?面向对象的三大特征 ...

  6. CString和string的互相转换

    CString->std::string 例子: CString strMfc=“test“; std::string strStl; strStl=strMfc.GetBuffer(0); s ...

  7. c++中智能输出文件

    首先我们要为每一时间步,设置一个文件名: ] = "; itoa(time,timestr,); std::string s; s += timestr; std::string path ...

  8. HTML第五天学习笔记

    今天先是学习了基础的css样式 <html> <head> <title></title> <meta http-equiv = "co ...

  9. 【java开发系列】— JDOM创建、改动、删除、读取XML文件

    有非常多中操作XML文件的方法,这里介绍一下JDOM的用法和技巧. JDOM下载地址 创建XML文档 XML文件是一种典型的树形文件,每一个文档元素都是一个document元素的子节点. 而每一个子元 ...

  10. JAVA组程序优化综合考试试题

    题目原型: 有一张标准的树状结构表,里面有Structure_Id和 Parent_Id两个关键列,记录了结点的父子关系.现在要求添加一个字段为 Structure_Code ,标记为 三位一个节点关 ...