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;
}
posted @ 2026-02-05 20:05  AnoSky  阅读(14)  评论(0)    收藏  举报