HDU 5056 Boring count(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5056
For each case, the first line contains a string which only consist of lowercase letters. The second line contains an integer K.
[Technical Specification]
1<=T<= 100
1 <= the length of S <= 100000
1 <= K <= 100000
3
abc
1
abcabc
1
abcabc
2
6
15
21
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjg2MDA2Mw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
#include <cstdio>
#include <cstring>
const int maxn = 100017;
int main()
{
int t;
char str[maxn];
int st[27];
int k;
scanf("%d",&t);
while(t--)
{
memset(st,0,sizeof(st));
scanf("%s",str);
scanf("%d",&k);
__int64 ans = 0;
int len = strlen(str);
int startpos = 0;
for(int i = 0; i < len; i++)
{
int tt = str[i] -'a';
st[tt]++;
if(st[tt] > k)
{
while(str[startpos]!=str[i])
{
st[str[startpos]-'a']--;
startpos++;
}
st[str[startpos]-'a']--;
startpos++;
}
ans+=i-startpos+1;
}
printf("%I64d\n",ans);
}
return 0;
}
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
贪心算法.需要计算分别以每个字母结尾的且每个字母出现的次数不超过k的字符串,我们设定一个初始位置s,然后用游标i从头到尾遍历字符串,使用map记录期间各个字母出现的次数,如果以s开头i结尾的字符串满足 ...
- HDU 5056 Boring Count --统计
题解见官方题解,我这里只实现一下,其实官方题解好像有一点问题诶,比如 while( str[startPos] != str[i+1] ) cnt[str[startPos]]--, startPos ...
- 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 ...
- 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 ...
- hdu 4961 Boring Sum(高效)
pid=4961" target="_blank" style="">题目链接:hdu 4961 Boring Sum 题目大意:给定ai数组; ...
随机推荐
- hdu 2189 dp
/* 类似完全背包,容量为n的背包用素数填,求满背包的种数 dp(i,j)表示用不超过i的素数组成的j的种数 dp[i][j]=dp[i-1][j],若i为素数则dp[i][j]+=dp[i][j-i ...
- 阿里巴巴Java开发手册公开版(转)
1.不要嫌名字长 无论是方法,变量,还是函数的取名,不要嫌弃名称太长,只要能够表示清楚含义就可以了. 2.String[] args而不是String args[] 中括号是数组类型的一部分,数组定义 ...
- VS Code开发技巧集锦【转】
转自:http://blog.csdn.net/tiantangyouzui/article/details/52163175 入门 自定义 扩展 文件/文件夹管理 编辑技巧 智能感应功能 代码片段 ...
- Python 复习-1
#!/usr/bin/env python # -*- coding:utf-8 -*- # @Time : 2017/10/27 22:46 # @Author : lijunjiang # @Fi ...
- PHP操作MongoDB(增删改查)
MongoDB的PHP驱动提供了一些核心类来操作MongoDB,总的来说MongoDB命令行中有的功能,它都可以实现,而且参数的格式基本相似.PHP7以前的版本和PHP7之后的版本对MongoDB的操 ...
- LeetCode OJ-- Text Justification
https://oj.leetcode.com/problems/text-justification/ 细节题 class Solution { public: vector<string&g ...
- 用Wireshark分析Socket连接建立的过程
0. 安装Wireshark,但是默认情况下,Wireshark无法捕获127.0.0.1的报文 解决方案:安装npcap,替换默认的winpacp,重新启动Wireshark,就可以看到一个名字中含 ...
- (6)centos安装和解压
一.rpm包安装方式步骤:1.找到相应的软件包,比如soft.version.rpm,下载到本机某个目录:2.打开一个终端,su -成root用户:3.cd soft.version.rpm所在的目录 ...
- CSU-ACM2018寒假集训选拔-入门题
[题目链接]:http://vj.bit-studio.cn/contest/205664#overview A: [给你一个长度为n的序列,尾部插入再反转,求n次后最终序列][规律/思维] [分析] ...
- Ansible之Playbook详解
1.Playbook详解 playbook是一个非常简单的配置管理和多主机部署系统,可以定制配置,可以按照指定的操作步骤有序执行,支持同步和异步方式. 核心元素 Hosts:主机 Tasks:任务,由 ...