我是靠谱客的博主 美丽白猫,这篇文章主要介绍hdu 1387 Team Queue 优先队列,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <cstdio> #include <cstring> #include <cmath> #include <queue> #include <stack> #include <iostream> #include <algorithm> using namespace std; const int maxn=1e6+10; int c[1010],vis[1010]; int f[maxn]; struct node{ int w,m; int name; bool operator <(const node a)const{ if(w==a.w)return m>a.m; return w>a.w; } }e,g; char s[11]; int main() { int t,n,tt=0; while(scanf("%d",&t)!=EOF) { if(t==0)break; memset(f,0,sizeof(f)); memset(c,0,sizeof(c)); int i,j,k,a,num=0; for(i=1;i<=t;i++) { scanf("%d",&n); for(j=0;j<n;j++) { scanf("%d",&a); f[a]=i; } } priority_queue<node>q; printf("Scenario #%dn",++tt); int d=0; while(cin>>s) { if(strcmp(s,"STOP")==0)break; if(strcmp(s,"ENQUEUE")==0) { scanf("%d",&a); if(c[f[a]]) { c[f[a]]++; g.w=vis[f[a]]; g.name=a; g.m=d++; q.push(g); } else { c[f[a]]++; vis[f[a]]=num; g.w=num++; g.name=a; g.m=d++; q.push(g); } } else { g=q.top(); q.pop(); printf("%dn",g.name); c[f[g.name]]--; } } printf("n"); } return 0; }

最后

以上就是美丽白猫最近收集整理的关于hdu 1387 Team Queue 优先队列的全部内容,更多相关hdu内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(91)

评论列表共有 0 条评论

立即
投稿
返回
顶部