UVA12583_Memory Overow
题目是很简单的队列维护的题目。
每次加入之前判断该字母是否在队列以及队列的容量是否超过k即可。
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #define maxn 1666
- using namespace std;
- int q[maxn],inq[maxn];
- char s[maxn];
- int n,k,t,head,tail,ans,cas=;
- int main()
- {
- scanf("%d",&t);
- while (t--)
- {
- scanf("%d%d",&n,&k);
- scanf("%s",s);
- head=,ans=tail=;
- memset(inq,false,sizeof inq);
- for (int i=; s[i]; i++)
- {
- if (inq[int(s[i])]) ans++;
- q[++tail]=int(s[i]);
- if (tail-head+>k)
- {
- inq[q[head++]]=false;
- }
- for (int j=head; j<=tail; j++) inq[q[j]]=true;
- }
- printf("Case %d: %d\n",++cas,ans);
- }
- return ;
- }
UVA12583_Memory Overow的更多相关文章
- 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 ...
- [轉]Exploit Linux Kernel Slub Overflow
Exploit Linux Kernel Slub Overflow By wzt 一.前言 最近几年关于kernel exploit的研究比较热门,常见的内核提权漏洞大致可以分为几类: 空指针引用, ...
随机推荐
- [BZOJ3678]wangxz与OJ-[Splay一类的平衡树]
Description 传送门 Solution 直接splay搞定吧..似乎非旋treap也ok? 我已经菜到模板题都写不出来了qaq Code #include<iostream> # ...
- 【转载】C/C++杂记:虚函数的实现的基本原理
原文:C/C++杂记:虚函数的实现的基本原理 1. 概述 简单地说,每一个含有虚函数(无论是其本身的,还是继承而来的)的类都至少有一个与之对应的虚函数表,其中存放着该类所有的虚函数对应的函数指针.例: ...
- day 7 __new___
1 __new__方法 创建对象 实质是:调用父类的__new__方法创建的对象 class Dog(object): def __init__(self): print("---init方 ...
- 【LG3233】[HNOI2014]世界树
题面 洛谷 题解 代码 #include <iostream> #include <cstdio> #include <cstdlib> #include < ...
- 【LG3231】[HNOI2013]消毒
题面 洛谷 题解 代码 \(100pts\) #include<iostream> #include<cstdio> #include<cstdlib> #incl ...
- 中国天气网 城市代码 sql语句
mysql的 下载地址:http://download.csdn.net/detail/songzhengdong82/6252651
- 转 gerrit
开发环境 https://blog.csdn.net/u013207966/article/details/79112740 先记录下我的开发环境以及要正确安装gerrit需要用到的工具: Redha ...
- 【UGUI】 (一)------- 放大镜
在许多游戏或应用中,我们常常看到放大镜的身影,而在Unity里面,制作一个简易的放大镜是非常简单的. 一. 创建一个3DObject 创建一个Cube或者 Cylinder,这里为了更像放大镜一 ...
- Windows和Linux系统如何退出python命令行
python命令行是新手学习python过程中必须要学的一个工具,下面我们来看一下怎么退出python命令行. 第一种方式: 使用python提供的exit()函数,linux平台和windows平台 ...
- PowerDesigne 建立概念数据模型
本文主要介绍PowerDesigner概念数据模型以及实体.属性创建. 一.新建概念数据模型1)选择File-->New,弹出如图所示对话框,选择CDM模型(即概念数据模型)建立模型. 2)完成 ...