luogu1540【2010提高】机器翻译(队列)

xiaoxiao2021-02-28  94

按题意模拟即可。

#include <cstdio> #include <cstring> #include <queue> #define N 1005 inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f; } int n,m,ans=0; bool f[N]; std::queue<int> q; int main(){ // freopen("a.in","r",stdin); m=read();n=read(); while(n--){ int x=read(); if(f[x]) continue; ans++;f[x]=1; if(q.size()<m) q.push(x); else f[q.front()]=0,q.pop(),q.push(x); } printf("%d\n",ans); return 0; }
转载请注明原文地址: https://www.6miu.com/read-96698.html

最新回复(0)