洛谷p1540—机器翻译

题目https://www.luogu.org/problemnew/show/P1540

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[1010], b[1010];
int main()
{
	int n, m;
	int x;
	int l = 0, r = 0;
	int ans=0;
	cin >> m >> n;
	for (int i=1; i <= n; i++)
	{
		cin >> x;
		if (a[x] == 0)
		{
			ans++;
			r++;
			b[r] = x;
			a[x] = 1;
			if (r > m)
			{
				l++;
				a[b[l]] = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/fengzhongzhuifeng/p/10799783.html