P1540 [NOIP 2010 提高组] 机器翻译
点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
bool st[N];
queue<int> q;
int m,n;
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>m>>n;
int ans=0;
for(int i=1;i<=n;i++){
int word;
cin>>word;
if(st[word]){
continue;
}else{
ans++;
if(q.size()>=m){
int out=q.front();
q.pop();
st[out]=false;
}
q.push(word);
st[word]=true;
}
}
cout<<ans<<endl;
return 0;
}

浙公网安备 33010602011771号