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 <cstdl…
Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 828    Accepted Submission(s): 342 Problem Description You are given a string S consisting of lowercase letters, and your task is co…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5056 Problem Description You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more t…
贪心算法.需要计算分别以每个字母结尾的且每个字母出现的次数不超过k的字符串,我们设定一个初始位置s,然后用游标i从头到尾遍历字符串,使用map记录期间各个字母出现的次数,如果以s开头i结尾的字符串满足要求,则把结果增加i-s+1.否则的话向前移动s,不断维护map,直到s指向的字母与i相同,从而满足字符串条件,把结果增加i-s+1. 需要注意的是结果可能会超int,需要用long long. 代码如下: #define MAXS 100002 #include <cstdlib> #inclu…
You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.   Input In the first line there is an integer T , indicates the n…
给一个由小写字母构成的字符串S,问有多少个子串满足:在这个子串中每个字母的个数都不超过K. 数据范围: 1<=T<= 1001 <= the length of S <= 1000001 <= K <= 100000 思路: 考虑以S[i]结尾的子串,若以S[j] (j<i)作为头不能构成一个符合条件的子串,则S[1]...S[j]都不能作为子串的头. 若S[j+1]可以作为子串的头,则以S[i]结尾的符合条件的子串个数是i-j. 做法:单调队列的思想,不多解释,…
Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 360    Accepted Submission(s): 140 Problem Description You are given a string S consisting of lowercase letters, and your task is co…
起因:最近在学习mysql的数据库,发现在innodb表中大数据量下count(*)的统计结果实在是太慢,所以想找个办法替代这种查询,下面分享一下我查找的过程. 实践:在给出具体的结论之前,我们先看看下面的现象. 一.     创建数据库 创建数据库的表语句如下: create database IF NOT EXISTS MY_TEST default charset utf8  COLLATE utf8_general_ci; 二.     创建User表 创建User表的语句如下,User…
Boring count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 787 Accepted Submission(s): 325 Problem Description You are given a string S consisting of lowercase letters, and your task is counting…
Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 228    Accepted Submission(s): 90 Problem Description You are given a string S consisting of lowercase letters, and your task is coun…