璟雯院

珺璟如晔,雯华若锦

用户工具

站点工具


icpc:problems:luogup1540
problems
名称机器翻译
题目编号2010 NOIP TG T1
题目链接luogu.com.cn/…
来源CCF
算法分类队列
难易程度容易

机器翻译

想法

队列模拟,查找不到进行增加,位数超过了进行出队。

代码实现

#include<cstdio>
 
int line[1010];
 
int main() {
	int m, n, temp, head = 0, last = -1, cnt = 0;
	scanf("%d %d", &m, &n);
	for(int i=1; i<=n; i++) {
		scanf("%d", &temp);
		bool flag = false;
		for(int j=head; j<=last; j++) 
			if(line[j] == temp){
				flag = true;
				break;
			}
		if(!flag) {
			line[++last] = temp;
			cnt++;
			while(last - head + 1 > m)
				head++;
		}
	}
	printf("%d", cnt);
	return 0;
}
/app/www/public/data/pages/icpc/problems/luogup1540.txt · 最后更改: 2024/03/14 00:56 由 温婕莺