您的位置:首页 > 其它

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

2017-09-01 21:16 148 查看
按题意模拟即可。

#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
;
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: