UVA-12100 Printer Queue

本文通过一个具体的C++程序实例,展示了如何使用标准模板库(STL)中的队列(queue)进行数据处理,以及如何结合算法进行有效的数据操作。通过对输入数据的处理和特定条件下的操作,该程序为理解C++中的数据结构和算法提供了实用的参考。
 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <queue>
 5 #include <cstring>
 6 #include <cmath>
 7 
 8 using namespace std;
 9 
10 int main ()
11 {
12     int N;
13     cin >> N;
14     while(N--)
15     {
16         int n,m;
17         cin >> n >> m;
18         queue<int> q;
19         int List[11];
20         memset(List,0,sizeof(List));
21         while(n--)
22         {
23             int tmp;
24             cin >> tmp;
25             if(m == 0)
26             {
27                 q.push(-tmp);
28                 m --;
29             }
30             else
31             {
32                 q.push(tmp);
33                 m --;
34             }
35             List[tmp] ++;
36         }
37 
38         int time = 0;
39         while(!q.empty())
40         {
41             int i;
42             for(i = abs(q.front())+1;i <= 9;i ++)
43             {
44                 if(List[i])
45                 {
46                      int a = q.front();
47                      q.pop();
48                      q.push(a);
49                      break;
50                 }
51             }
52             if(i==10)
53             {
54                 List[abs(q.front())] --;
55                 if(q.front()<0)
56                 {
57                     time ++;
58                     break;
59                 }
60                 q.pop();
61                 time ++;
62             }
63         //    cout << q.front() << " ";
64         }
65         cout << time << endl;
66     }
67     return 0;
68 }

 

转载于:https://www.cnblogs.com/Asurudo/p/9724178.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值