题目
模拟进队出队的情况设两个指针,进行移动。
#include<iostream>
#include<cstdio>
using namespace std;
int n,m;
int a[200],ans,l,r;
bool f[1100];
int main()
{
scanf("%d%d",&m,&n);l=0;r=0;
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);
if(!f[x])
{
ans++;
if(r<m)
{
r++;a[r]=x;f[x]=1;
}
else if(r==m)
{
l++;if(l==m+1) l=1;
f[a[l]]=0;
a[l]=x;
f[x]=1;
}
}
}
cout<<ans;
return 0;
}