洛谷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;
}

  

posted @ 2019-05-01 14:19  Fzzf1  阅读(190)  评论(0编辑  收藏  举报