#include<iostream>
#include<queue>
using namespace std;
int main()
{
int m,n=0;
//接收m,n的输入
cin>>m>>n;
//用哈希表表示单词是否在内存中,1为存在,0为不存在
int hash[1000]={0};
//用队列表示内存
queue<int> q;
//查询外存次数
int cnt=0;
while(n>0)
{
//单词输入
int word=0;
cin>>word;
if(hash[word]!=1)
{
q.push(word);
hash[word]=1;
cnt++;
//内存超界处理
if(q.size()>m)
{
hash[q.front()]=0;
q.pop();
}
}
n--;
}
cout<<cnt;
}
队列--洛谷P1540
最新推荐文章于 2024-08-06 18:21:23 发布