解题思路:按照队列的思想依次引入单词,并附加st来记录单词是否已经学过。
注意事项:
参考代码:
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int N = 100010;
int main()
{
queue<int> q;
int m, n, ans = 0;
cin >> m >> n;
bool st[N];
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
if (!st[x])
{
q.push(x);
if (q.size() <= m)
{
st[x] = true;
ans++;
}
if (q.size() > m)
{
st[q.front()] = false;
q.pop();
st[x] = true;
ans++;
}
}
}
cout << ans << endl;
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1034 |
【数组的距离】 (C语言代码)浏览:742 |
【简单计算】 (C语言代码)浏览:622 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:648 |
1642题解浏览:716 |
1011题解浏览:766 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:569 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:812 |
1014题解浏览:485 |
C二级辅导-阶乘数列 (C语言代码)浏览:522 |