P1540 [NOIP2010 提高组] 机器翻译 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
这题就是用stl向量容器模拟队列过程
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, m, ans;
vector<int> q;
int main()
{
cin >> m >> n;
while(n -- )
{
int x;
cin >> x;
if(find(q.begin(), q.end(), x) == q.end())//没找到,就会返回q.end()值
{
q.push_back(x);
ans ++;
}
if(q.size() > m) q.erase(q.begin()); //队头出队
}
cout << ans;
return 0;
}
也可以用queue或deque 但是查找元素(查字典过程)就不能用find()函数了,www