cf C. Dima and Containers

http://codeforces.com/contest/358/problem/C

将最大的放在stack里面,第二大的放在queue中,第三大的放在deck里面。然后模拟就可以了。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <queue>
 4 #include <algorithm>
 5 using namespace std;
 6 int a[100010];
 7 
 8 priority_queue<int ,vector<int>,less<int> >q;
 9 int n;
10 
11 int main()
12 {
13     scanf("%d",&n);
14     for(int i=1; i<=n; i++)
15     {
16         scanf("%d",&a[i]);
17     }
18     for(int i=1; i<=n; i++)
19     {
20         int t1=0;
21         int k=i;
22         while(1)
23         {
24             if(a[i]==0||i==n) break;
25             q.push(a[i]);
26             i++;
27         }
28         int max1=0,max2=0,max3=0;
29         if(!q.empty())
30         {
31             max1=q.top();
32             q.pop();
33             t1++;
34         }
35         if(!q.empty())
36         {
37             max2=q.top();
38             q.pop();
39             t1++;
40         }
41         if(!q.empty())
42         {
43             max3=q.top();
44             q.pop();
45             t1++;
46         }
47         for(int j=k; j<=i; j++)
48         {
49             if(a[j]==max1&&max1)
50             {
51                 max1=0;
52                 printf("pushStack
");
53             }
54             else if(a[j]==max2&&max2)
55             {
56                 max2=0;
57                 printf("pushQueue
");
58             }
59             else if(a[j]==max3&&max3)
60             {
61                 max3=0;
62                 printf("pushFront
");
63             }
64             else if(a[j]!=0) printf("pushBack
");
65         }
66         if(a[i]==0)
67         {
68             if(t1==0)
69                 printf("%d
",0);
70             else printf("%d",t1);
71             if(t1>=3)
72             {
73                 printf(" popStack popQueue popFront
");
74             }
75             else if(t1>=2)
76             {
77                 printf(" popStack popQueue
");
78             }
79             else if(t1>=1)
80             {
81                 printf(" popStack
");
82             }
83             while(!q.empty())
84             {
85                 q.pop();
86             }
87         }
88     }
89     return 0;
90 }
View Code
原文地址:https://www.cnblogs.com/fanminghui/p/3936546.html