各位大佬帮忙看一下,一堆WA
查看原帖
各位大佬帮忙看一下,一堆WA
1411725
hushuoyan楼主2024/8/1 16:55
#include <iostream>
#include <queue>
#include <set>
using namespace std;

int m,n;
int a[1010];
queue<int> q;
int sum;

bool hav(int key){
	bool f;
	set<int> t;
	while (!q.empty()){
		t.insert(q.front());
		q.pop();
	}
	if (t.find(key) != t.end()) f = 1;
	else f = 0;
	for (const int i : t){
		q.push(i);
	}
	return f;
}

int main(){
	cin >> m >> n;
	for (int i = 1;i <= n;i++){
		cin >> a[i];
		if (!hav(a[i])){
			sum++;
			q.push(a[i]);
		}
		if (q.size() > m){
			q.pop();
		}
	}
	cout << sum;
	return 0;
}
2024/8/1 16:55
加载中...