用一个队列模拟,还有一个数组cnt记录9个优先级的任务的数量,每次找到当前最大优先级的任务然后出队,并及时更新cnt数组。

 #include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std; struct Task
{
int pos, pri;
Task(int pos = , int pri = ):pos(pos), pri(pri) {}
}; int cnt[]; int main()
{
//freopen("in.txt", "r", stdin); int T; scanf("%d", &T);
while(T--)
{
int n, p;
scanf("%d%d", &n, &p);
memset(cnt, , sizeof(cnt));
queue<Task> Q;
for(int i = ; i < n; i++)
{
int pri;
scanf("%d", &pri);
Q.push(Task(i, pri));
cnt[pri]++;
}
while()
{
Task t = Q.front();
int m;
for(m = ; m >= t.pri; m--) if(cnt[m]) break;
cnt[m]--;
if(m > t.pri)
{
while(t.pri != m)
{
Q.pop();
Q.push(t);
t = Q.front();
}
Q.pop();
if(t.pos == p) break;
//printf("sz = %d\n", Q.size());
}
else
{
Q.pop();
if(t.pos == p) break;
}
}
printf("%d\n", n - Q.size());
} return ;
}

代码君

UVa 12100 (模拟) Printer Queue的更多相关文章

  1. 【习题 5-7 UVA - 12100】Printer Queue

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用队列和multiset就能完成模拟 [代码] #include <bits/stdc++.h> using names ...

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

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

  3. uva 12100 Printer Queue

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

  4. Printer Queue UVA - 12100

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

  5. 12100 Printer Queue(优先队列)

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

  6. Printer Queue

    Description The only printer in the computer science students' union is experiencing an extremely he ...

  7. POJ 3125 Printer Queue

    题目: Description The only printer in the computer science students' union is experiencing an extremel ...

  8. [刷题]算法竞赛入门经典(第2版) 5-7/UVa12100 - Printer Queue

    题意:一堆文件但只有一个打印机,按优先级与排队顺序进行打印.也就是在一个可以插队的的队列里,问你何时可以打印到.至于这个插队啊,题目说"Of course, those annoying t ...

  9. J - Printer Queue 优先队列与队列

    来源poj3125 The only printer in the computer science students' union is experiencing an extremely heav ...

随机推荐

  1. 将Asp.Net页面输出到EXCEL里去

    其实,利用ASP.NET输出指定内容的WORD.EXCEL.TXT.HTM等类型的文档很容易的.主要分为三步来完成. 一.定义文档类型.字符编码   Response.Clear(); Respons ...

  2. 利用Jquery实现http长连接(LongPoll) {转}

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="JqueryAjaxLongPo ...

  3. Appstore提交 被拒绝

    Reasons 16.1: Apps that present excessively objectionable or crude content will be rejected 16.1 We ...

  4. 迁移到MariaDB galera

    迁移到MariaDB galera [已注销] [已注销] -- :: [安装] ====== https://downloads.mariadb.org/mariadb/repositories/ ...

  5. LA 4727

    Integers 1, 2, 3,..., n are placed on a circle in the increasing order as in the following figure. W ...

  6. 为jquery qrcode生成的二维码嵌入图片

    在一次微信项目中,需要实现通过扫描二维码来进行会议签到,二维码的生成选择了qrcode.js的版本,然后使用jquery.qrcode.js插件来绘制二维码. <script type=&quo ...

  7. asp.net dataTable添加列

    DataTable dtNew = new DataTable(); dtNew.Columns.Add("ItemNo");//序列号列 dtNew.Columns.Add(&q ...

  8. lintcode:线段树的修改

    线段树的修改 对于一棵 最大线段树, 每个节点包含一个额外的 max 属性,用于存储该节点所代表区间的最大值. 设计一个 modify 的方法,接受三个参数 root. index 和 value.该 ...

  9. 可灵活扩展的自定义Session状态存储驱动

    Session是互联网应用中非常重要的玩意儿,对于超过单台部署的站点集群,都会存在会话共享的需求.在web.config中,微软提供了sessionstate节点来定义不同的Session状态存储方式 ...

  10. switch中的default的位置

    [转载]http://hi.baidu.com/dannie007zxl/item/5d0c3185577df719c3162724 有的时候,我们对身旁自认为熟悉的东西,却发现很难去给出准确的回答. ...