我是靠谱客的博主 唠叨飞鸟,这篇文章主要介绍540 - 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
题目的意思就是排队买票问题,就像好多班在买票,前面如果有和自己买票的就可以插队,但是只能插到自己班的最后一名,如果没有自己班的排队买票就只能在所有人后面慢慢排队买票了,我采用了栈以及数组和链表,但是一般不要用stl,要不然很容易超时,第一次提交时完全用的stl所以超时了……下面是代码 第一次提交的代码,但是超时了…… #include <iostream> #include <cstdio> #include <stack> #include <cstdlib> #include <queue> #include <cstring> #include <list> #include <vector> #include <algorithm> usingnamespacestd; typedefqueue<int> q; typedeflist<int> l; intmain() { //freopen("a.txt","r",stdin); intn,c(1); while(scanf("%d",&n)!=EOF) { if(n==0)break; else { printf("Scenario #%dn",c); vector<l> v; v.clear(); intm,x; while(n--) { scanf("%d",&m); l list1; list1.clear(); while(m--) { scanf("%d",&x); list1.push_back(x); } v.push_back(list1); } list<q> qu; list<q>::iterator p; qu.clear(); list<int> count; list<int>::iterator i; count.clear(); intflag(0); chars[10]; memset(s,0,sizeof(s)); while(scanf("%s",s)!=EOF) { if(strcmp(s,"STOP")==0)break; elseif(strcmp(s,"ENQUEUE")==0) { scanf("%d",&m); flag++; for(x=0; x<v.size(); x++) { i=find(v[x].begin(),v[x].end(),m); if(i!=v[x].end())break; } if(flag>=2) { for(i=count.begin(),p=qu.begin(); i!=count.end(); p++, i++) if(*i==x)break; } elsei=count.end(); if(i==count.end()) { count.push_back(x); q queue1; queue1.push(m); qu.push_back(queue1); } else { (*p).push(m); flag--; } } elseif(strcmp(s,"DEQUEUE")==0) { printf("%dn",qu.front().front()); qu.front().pop(); if(qu.front().size()==0) { qu.pop_front(); count.pop_front(); } } memset(s,0,sizeof(s)); } printf("n"); } c++; } return0; } 第二次提交代码(没有超时,ac了): #include <iostream> #include <cstdio> #include <stack> #include <cstdlib> #include <queue> #include <cstring> #include <list> #include <vector> #include <algorithm> usingnamespacestd; longstr[1010][1010]; typedefqueue<long> q; intmain() { //freopen("a.txt","r",stdin); longn,cx(1); while(scanf("%ld",&n)!=EOF) { memset(str,0,sizeof(str)); if(n==0)break; else { printf("Scenario #%ldn",cx); longm,i(0),j,c,maxn(0); while(i<n) { scanf("%ld",&m); j=0; while(j<m) { scanf("%ld",&c); str[i][j++]=c; } i++; if(maxn<m)maxn=m; } list<q> l; list<q>::iterator p; l.clear(); list<long> count; list<long>::iterator k; count.clear(); chars[10]; memset(s,0,sizeof(s)); while(scanf("%s",s)!=EOF) { intflag(0); if(strcmp(s,"STOP")==0)break; elseif(strcmp(s,"ENQUEUE")==0) { scanf("%ld",&c); for(i=0; i<n; i++) { for(j=0; str[i][j]&&j<maxn; j++) if(c==str[i][j]) { flag=1; break; } if(flag==1)break; } if(count.size()>=1) { for(k=count.begin(),p=l.begin(); k!=count.end(); p++, k++) if(*k==i)break; } elsek=count.end(); if(k==count.end()) { count.push_back(i); q queue1; queue1.push(c); l.push_back(queue1); } else(*p).push(c); } elseif(strcmp(s,"DEQUEUE")==0) { printf("%ldn",l.front().front()); l.front().pop(); if(l.front().size()==0) { l.pop_front(); count.pop_front(); } } memset(s,0,sizeof(s)); } printf("n"); } cx++; } return0; }

最后

以上就是唠叨飞鸟最近收集整理的关于540 - Team Queue的全部内容,更多相关540内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部