打印队列 (Printer Queue,ACM/ICPC NWERC 2006,UVA12100)

题目描述:

题目思路:

使用一个队列记录数字,一个优先队列记录优先级,如果相等即可打印;

 1 #include <iostream>
 2 #include <queue>
 3 using namespace std;
 4 int main(int argc, char *argv[])
 5 {
 6     int t;
 7     cin >> t;
 8     while(t--)
 9     {
10         int n,pos;
11         queue<int> q ;
12         priority_queue<int> pq ;
13         cin >> n >> pos ;
14         for(int i=0;i<n;i++)
15         {
16             int a;
17             cin >> a;
18             q.push(a);
19             pq.push(a);
20         }
21         int t = 0;
22         while(true)
23         {
24             if(q.front() == pq.top())
25             {
26                 if(t==pos){cout<<n-q.size()+1<<endl;break;}
27                 else{
28                     q.pop();
29                     pq.pop();
30                     t++;
31                 }
32             }
33             else{
34                 int temp = q.front();
35                 q.pop();
36                 q.push(temp);
37                 if(t == pos){t=0;pos=q.size()-1;}
38                 else t++ ;
39
40             }
41         }
42     }
43     return 0;
44 }

原文地址:https://www.cnblogs.com/secoding/p/9495600.html

时间: 2024-07-29 22:06:45

打印队列 (Printer Queue,ACM/ICPC NWERC 2006,UVA12100)的相关文章

集合栈计算机(The Set Stack Computer,ACM/ICPC NWERC 2006,UVa12096)

集合栈计算机(The Set Stack Computer,ACM/ICPC NWERC 2006,UVa12096) 对于集合的集合,很难直接表示,因此,为方便起见,为每个不同的集合分配一个不同的ID,每个集合都可以表示成所含集合的ID集合,一个集合就可以表示为一个set 我的理解: {}:1 {{}} 2 栈中的都是集合,所以也是int类型的 实际进行操作的过程中,可以用map将每种集合和对应的ID关联起来,这样做既可以完成查找ID的任务,还可以同时判定是否出现了新的集合. 用vector作

poj 3125 Printer Queue (队列)

 Printer Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3679   Accepted: 1975 Description The only printer in the computer science students' union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs i

POJ 3125 Printer Queue 数据结构 队列

Printer Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4329   Accepted: 2269 Description The only printer in the computer science students' union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in t

ACM/ICPC 之 数据结构-邻接表+DP+队列+拓扑排序(TshingHua OJ-旅行商TSP)

做这道题感觉异常激动,因为在下第一次接触拓扑排序啊= =,而且看了看解释,猛然发现此题可以用DP优化,然后一次A掉所有样例,整个人激动坏了,哇咔咔咔咔咔咔咔~ 咔咔~哎呀,笑岔了- -|| 旅行商(TSP) Description Shrek is a postman working in the mountain, whose routine work is sending mail to n villages. Unfortunately, road between villages is

UVa 12110 Printer Queue(特殊队列)

题意  模拟打印队列   队列中有优先级大于队首的元素   队首元素就排到队尾  否则队首元素出队  输出开始在p位置的元素是第几个出队的 直接模拟这个过程就行了 #include <bits/stdc++.h> using namespace std; const int N = 205; int q[N]; int main() { int cas, n, p, cnt, front, rear, i; scanf("%d", &cas); while(cas-

12100 Printer Queue(优先队列)

12100 Printer Queue12 The only printer in the computer science students’ union is experiencing an extremely heavy workload. Sometimes there are a hundred jobs in the printer queue and you may have to wait for hours to get a single page of output. Bec

2013 ACM/ICPC 长沙现场赛 A题 - Alice&#39;s Print Service (ZOJ 3726)

Alice's Print Service Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her print service found some tricks to save money. For example, the price when

2014 ACM/ICPC Asia Regional Xi&#39;an Online(HDU 5007 ~ HDU 5017)

题目链接 A题:(字符串查找,水题) 题意 :输入字符串,如果字符串中包含“ Apple”, “iPhone”, “iPod”, “iPad” 就输出 “MAI MAI MAI!”,如果出现 “Sony” 就输出“SONY DAFA IS GOOD!” ,大小写敏感. 思路 : 字符串查找,水题. 1 #include <string.h> 2 #include <stdio.h> 3 #include <iostream> 4 5 using namespace st

2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】

Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 591    Accepted Submission(s): 329 Problem Description Elves are very peculiar creatures. As we all know, they can live for a very