[NOIp2010] 机器翻译

水题。

洛谷 P1540 传送门

我就是没事儿闲的刷一刷洛谷试炼场。

我没有维护队列,而是维护了每个元素在队列里的位置。

本质上是个虚拟队列。

 1 #include<cstdio>
 2 
 3 int m,n,ans;
 4 int c[1005];
 5 int tot;
 6 
 7 int main()
 8 {
 9     scanf("%d%d",&m,&n);
10     for(int i=0;i<=1000;i++)c[i]=-0x3f3f3f3f;
11     for(int i=1;i<=n;i++)
12     {
13         int w;
14         scanf("%d",&w);
15         if(c[w]<=tot-m)c[w]=++tot,ans++;
16     }
17     printf("%d",ans);
18     return 0;
19 }

 

posted @ 2018-10-04 18:52  cervusky  阅读(220)  评论(0编辑  收藏  举报

Contact with me