You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
587 B
27 lines
587 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
const int N = 1010;
|
|
int m, n, cnt;
|
|
//思路:队列+桶
|
|
bool b[N]; //判断该数是否在内存中,桶。
|
|
queue<int> q; //定义一个队列
|
|
int main() {
|
|
cin >> m >> n;
|
|
for (int i = 1; i <= n; i++) {
|
|
int t;
|
|
cin >> t;
|
|
if (!b[t]) {
|
|
q.push(t);
|
|
b[t] = true;
|
|
cnt++;
|
|
if (q.size() > m) {
|
|
b[q.front()] = false;
|
|
q.pop();
|
|
}
|
|
}
|
|
}
|
|
printf("%d", cnt);//输出计数
|
|
return 0;
|
|
} |