20求助
查看原帖
20求助
703559
Zhyzhy123楼主2023/9/17 20:35
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
queue<int> q;
int m, n;
int res;
int exist[110];
int word[1010];
int main(){
	scanf("%d %d", &m, &n);
	for(int i = 0; i < n; i ++){
		scanf("%d", &word[i]);
		if(!exist[word[i]]){//如果该单词不在内存中 
			res ++;//访问外存次数 +1
			if(q.size() == m){//若内存已满 清理最先进来的单词 
				exist[q.front()] = 0;
				q.pop();
			}
			
			q.push(word[i]);//将该单词调入内存 
			exist[word[i]] = 1;//更新单词状态 
		}
	}
		
	cout << res;
}
2023/9/17 20:35
加载中...