题解 | 机器翻译
机器翻译
https://www.nowcoder.com/practice/45ecfecd83104f37a685016361be504c
#include <iostream>
#include <vector>
using namespace std;
#include <queue>
int main() {
int m, n;
cin >> m >> n;
queue<int> queue;
vector<int> shuzu(n);
for (int i = 0; i < n; i++) {
cin >> shuzu[i];
}
int miss = 0;
vector<int> jilu(1001);
for (int i = 0; i < jilu.size(); i++) {
jilu[i] = 0;
}
for (int i = 0; i < shuzu.size(); i++) {
if (jilu[shuzu[i]] < 1) {
if (queue.size() < m) {
queue.push(shuzu[i]);
jilu[shuzu[i]] = 1;
miss++;
}
else {
int qingling = queue.front();
jilu[qingling] = 0;
queue.pop();
queue.push(shuzu[i]);
jilu[shuzu[i]] = 1;
miss++;
}
continue;
}
else {
continue;
}
}
cout << miss << endl;
return 0;
}
// 64 位输出请用 printf("%lld")