HDU 5056 Boring Count --统计
题解见官方题解,我这里只实现一下,其实官方题解好像有一点问题诶,比如
while( str[startPos] != str[i+1] ) cnt[str[startPos]]--, startPos++;
那个str[i+1]的话会越界。应该是这样: while(str[startPos] != str[i])
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define lll __int64
using namespace std;
#define N 100007 char ss[N];
int cnt[]; int main()
{
int len,k,i,t;
scanf("%d",&t);
while(t--)
{
memset(ss,,sizeof(ss));
memset(cnt,,sizeof(cnt));
ss[] = '$';
scanf("%s",ss+);
len = strlen(ss+);
scanf("%d",&k);
int s = ;
lll ans = ;
for(i=;i<=len;i++)
{
cnt[ss[i]-'a']++;
if(cnt[ss[i]-'a'] > k)
{
while(ss[s] != ss[i])
cnt[ss[s]-'a']--, s++;
cnt[ss[s]-'a']--, s++;
}
ans += i-s+;
}
printf("%I64d\n",ans);
}
return ;
}
官方题解:

HDU 5056 Boring Count --统计的更多相关文章
- HDU 5056 Boring count(不超过k个字符的子串个数)
Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- HDU 5056 Boring count(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5056 Problem Description You are given a string S con ...
- hdu 5056 Boring count
贪心算法.需要计算分别以每个字母结尾的且每个字母出现的次数不超过k的字符串,我们设定一个初始位置s,然后用游标i从头到尾遍历字符串,使用map记录期间各个字母出现的次数,如果以s开头i结尾的字符串满足 ...
- hdu 5056 Boring count (窗体滑动)
You are given a string S consisting of lowercase letters, and your task is counting the number of su ...
- hdu 5056 Boring count (类似单调队列的做法。。)
给一个由小写字母构成的字符串S,问有多少个子串满足:在这个子串中每个字母的个数都不超过K. 数据范围: 1<=T<= 1001 <= the length of S <= 10 ...
- hdu Boring count(BestCode round #11)
Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- MySql的count统计结果
起因:最近在学习mysql的数据库,发现在innodb表中大数据量下count(*)的统计结果实在是太慢,所以想找个办法替代这种查询,下面分享一下我查找的过程. 实践:在给出具体的结论之前,我们先看看 ...
- Boring count(字符串处理)
Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu----(5056)Boring count(贪心)
Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
随机推荐
- H5调用Android拨打电话
1.AndroidAndJSInterface.java class AndroidAndJSInterface { /** * 该方法将被js调用,用于加载数据 */ @JavascriptInte ...
- 解决Spring MVC @ResponseBody返回html中中文字符串乱码问题
最近有个应用,通过responsebody返回完整的html页面时出现乱码是异常的问题,因为是通过responsebody返回,所以一开始设置了text/plain的字符集,如下: <mvc:a ...
- JavaScript 中有关数组对象的方法
JS 处理数组多种方法 js 中的数据类型分为两大类:原始类型和对象类型. 原始类型包括:数值.字符串.布尔值.null.undefined 对象类型包括:对象即是属性的集合,当然这里又两个特殊的对象 ...
- javascript宿主对象之window.location
location属性是一个用来存储当前页面URL信息的对象. 下面我们通过循环来列出location对象的完整属性列表: for(var i in location){ if(typeof locat ...
- JavaScript强化教程——Cocos2d-JS中JavaScript继承
javaScript语言本身没有提供类,没有其它语言的类继承机制,它的继承是通过对象的原型实现的,但这不能满足Cocos2d-JS引擎的要求.由于Cocos2d-JS引擎是从Cocos2d-x演变而来 ...
- How to install and configure Azure PowerShell
https://azure.microsoft.com/en-us/documentation/articles/powershell-install-configure/ In this artic ...
- Sharepoint学习笔记—习题系列--70-573习题解析 -(Q63-Q65)
Question 63You have a SharePoint farm that has more than 100 custom Features.You upgrade several Fea ...
- 百度Couldn't load BaiduMapSDK_v2_4_1 from loader dalvik
原文链接:http://liuzhichao.com/p/1463.html 在使用百度定位SDK的时候,明明已经加入了liblocSDK3.so,Manifest中也添加了相应权限,注册了com.b ...
- MyBatis入门(一)---基本使用
一.MyBatis简介 1.1.概述 MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架. MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. M ...
- 将tomcat源码导入eclipse
前言: 写完了socket小应用的原始版本,中间还有好多预想的功能没有实现,在写的过程中也发现了很多问题.因为前面有粗略的看过tomcat实现原理解析,知道tomcat其实也是纯java写的web服务 ...