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 由 温婕莺