<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">在线评测:</span>
http://codevs.cn/problem/1067/
整体思路:
就开个队列,开个vis数组模拟一下就好...
失误之处:
无
体会心得:
无
AC代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using
namespace
std;
int
m,n,tot,tp,ans;
queue <
int
> dl;
bool
vis[1000];
int
main()
{
scanf
(
"%d%d"
,&m,&n);
for
(
int
i = 1;i <= n;i++)
{
scanf
(
"%d"
,&tp);
if
(!vis[tp])
{
ans++;
if
(tot == m)
{
int
ftp = dl.front();
dl.pop();
vis[ftp] =
false
;
dl.push(tp);
vis[tp] =
true
;
}
else
{
tot++;
vis[tp] =
true
;
dl.push(tp);
}
}
}
printf
(
"%d"
,ans);
return
0;
}
|