用一个队列模拟,还有一个数组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. UnityException: Texture is not readable

    原地址:http://blog.csdn.net/emoonight/article/details/18002913 fore you can save or load a Texture, you ...

  2. linux gcc loudong

    五事九思 (大连Linux主机维护) 大连linux维护qq群:287800525 首页 日志 相册 音乐 收藏 博友 关于我     日志       spcark_0.0.3_i386.src.t ...

  3. VS2012 win7 修改TFS登陆账号

    1.修改登陆账号: 在网上搜了好多,都没有找到解决方法,自己琢磨了一会找到了修改登陆TFS(Team Foundation Server)(团队资源管理器)的账号,和大家分享一下吧. 点击“开始”-- ...

  4. ZOJ3550 Big Keng(三分)

    题意:给定一个立体的图形,上面是圆柱,下面是圆台,圆柱的底面半径和圆台的上半径相等,然后体积的V时,问这个图形的表面积最小可以是多少.(不算上表面).一开始拿到题以为可以YY出一个结果,就认为它是圆锥 ...

  5. POJ 2785

    4 Values whose Sum is 0 Time Limit: 15000MS   Memory Limit: 228000K Total Submissions: 14475   Accep ...

  6. Linux的别名使用

    直接定义别名 编辑当前用户下的.bashrc 文件: vim  ~/.bashrc 添加别名为 lmysql 的命令语句 : alias lmysql='mysql -uroot -p -Dtest ...

  7. SiteView

    http://www.siteview.com/cms/sites/public/home.html

  8. ExtJs之进度条实现

    慢慢按书上的作. <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta h ...

  9. GridControl的列显示成图片+文字,并且不同的文字对应不同的图片

    public static void SetDispatchStatus(GridView aGridView1, GridColumn aColStatus, bool aOnlyImage) { ...

  10. poj 2975 Nim 博弈论

    令ans=a1^a2^...^an,如果需要构造出异或值为0的数, 而且由于只能操作一堆石子,所以对于某堆石子ai,现在对于ans^ai,就是除了ai以外其他的石子 的异或值,如果ans^ai< ...