题目是很简单的队列维护的题目。

每次加入之前判断该字母是否在队列以及队列的容量是否超过k即可。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #define maxn 1666
  5. using namespace std;
  6.  
  7. int q[maxn],inq[maxn];
  8. char s[maxn];
  9. int n,k,t,head,tail,ans,cas=;
  10.  
  11. int main()
  12. {
  13. scanf("%d",&t);
  14. while (t--)
  15. {
  16. scanf("%d%d",&n,&k);
  17. scanf("%s",s);
  18. head=,ans=tail=;
  19. memset(inq,false,sizeof inq);
  20. for (int i=; s[i]; i++)
  21. {
  22. if (inq[int(s[i])]) ans++;
  23. q[++tail]=int(s[i]);
  24. if (tail-head+>k)
  25. {
  26. inq[q[head++]]=false;
  27. }
  28. for (int j=head; j<=tail; j++) inq[q[j]]=true;
  29. }
  30. printf("Case %d: %d\n",++cas,ans);
  31. }
  32. return ;
  33. }

UVA12583_Memory Overow的更多相关文章

  1. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem L. Stock Trading Robot 水题

    Problem L. Stock Trading Robot 题目连接: http://www.codeforces.com/gym/100253 Description CyberTrader is ...

  2. [轉]Exploit Linux Kernel Slub Overflow

    Exploit Linux Kernel Slub Overflow By wzt 一.前言 最近几年关于kernel exploit的研究比较热门,常见的内核提权漏洞大致可以分为几类: 空指针引用, ...

随机推荐

  1. [BZOJ3678]wangxz与OJ-[Splay一类的平衡树]

    Description 传送门 Solution 直接splay搞定吧..似乎非旋treap也ok? 我已经菜到模板题都写不出来了qaq Code #include<iostream> # ...

  2. 【转载】C/C++杂记:虚函数的实现的基本原理

    原文:C/C++杂记:虚函数的实现的基本原理 1. 概述 简单地说,每一个含有虚函数(无论是其本身的,还是继承而来的)的类都至少有一个与之对应的虚函数表,其中存放着该类所有的虚函数对应的函数指针.例: ...

  3. day 7 __new___

    1 __new__方法 创建对象 实质是:调用父类的__new__方法创建的对象 class Dog(object): def __init__(self): print("---init方 ...

  4. 【LG3233】[HNOI2014]世界树

    题面 洛谷 题解 代码 #include <iostream> #include <cstdio> #include <cstdlib> #include < ...

  5. 【LG3231】[HNOI2013]消毒

    题面 洛谷 题解 代码 \(100pts\) #include<iostream> #include<cstdio> #include<cstdlib> #incl ...

  6. 中国天气网 城市代码 sql语句

    mysql的 下载地址:http://download.csdn.net/detail/songzhengdong82/6252651

  7. 转 gerrit

    开发环境 https://blog.csdn.net/u013207966/article/details/79112740 先记录下我的开发环境以及要正确安装gerrit需要用到的工具: Redha ...

  8. 【UGUI】 (一)------- 放大镜

    在许多游戏或应用中,我们常常看到放大镜的身影,而在Unity里面,制作一个简易的放大镜是非常简单的.    一. 创建一个3DObject 创建一个Cube或者 Cylinder,这里为了更像放大镜一 ...

  9. Windows和Linux系统如何退出python命令行

    python命令行是新手学习python过程中必须要学的一个工具,下面我们来看一下怎么退出python命令行. 第一种方式: 使用python提供的exit()函数,linux平台和windows平台 ...

  10. PowerDesigne 建立概念数据模型

    本文主要介绍PowerDesigner概念数据模型以及实体.属性创建. 一.新建概念数据模型1)选择File-->New,弹出如图所示对话框,选择CDM模型(即概念数据模型)建立模型. 2)完成 ...