String

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 4821
64-bit integer IO format: %I64d      Java class name: Main

 
Given a string S and two integers L and M, we consider a substring of S as “recoverable” if and only if
  (i) It is of length M*L;
  (ii) It can be constructed by concatenating M “diversified” substrings of S, where each of these substrings has length L; two strings are considered as “diversified” if they don’t have the same character for every position.

Two substrings of S are considered as “different” if they are cut from different part of S. For example, string "aa" has 3 different substrings "aa", "a" and "a".

Your task is to calculate the number of different “recoverable” substrings of S.

 

Input

The input contains multiple test cases, proceeding to the End of File.

The first line of each test case has two space-separated integers M and L.

The second ine of each test case has a string S, which consists of only lowercase letters.

The length of S is not larger than 10^5, and 1 ≤ M * L ≤ the length of S.

 

Output

For each test case, output the answer in a single line.

 

Sample Input

3 3
abcabcbcaabc

Sample Output

2

Source

 
解题:字符串hash+map
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#include <map>
#define LL long long
#define ULL unsigned long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define seek 131
using namespace std;
const int maxn = ;
map<ULL,int>mp;
char str[maxn];
ULL base[maxn],hs[maxn];
int main() {
int M,L,len,i,j,ans;
ULL tmp;
base[] = ;
for(i = ; i < maxn; i++) base[i] = base[i-]*seek;
while(~scanf("%d%d%s",&M,&L,str)){
len = strlen(str);
ans = ;
hs[len] = ;
for(i = len-; i >= ; i--)
hs[i] = hs[i+]*seek+str[i]-'a';
for(i = ; i < L && i + M*L <= len; i++){
mp.clear();
for(j = i; j < i+M*L; j += L){
tmp = hs[j] - hs[j+L]*base[L];
mp[tmp]++;
}
if(mp.size() == M) ans++;
for(j = i+M*L; j+L <= len; j += L){
tmp = hs[j-M*L] - hs[j-M*L+L]*base[L];
mp[tmp]--;
if(!mp[tmp]) mp.erase(tmp);
tmp = hs[j] - hs[j+L]*base[L];
mp[tmp]++;
if(mp.size() == M) ans++;
}
}
printf("%d\n",ans);
}
return ;
}

HDU 482 String的更多相关文章

  1. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  2. HDU 3374 String Problem(KMP+最大/最小表示)

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. hdu 5772 String problem 最大权闭合子图

    String problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5772 Description This is a simple pro ...

  4. HDU 4821 String(2013长春现场赛I题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4821 字符串题. 现场使用字符串HASH乱搞的. 枚举开头! #include <stdio.h ...

  5. HDU 2476 String painter(区间DP+思维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2476 题目大意:给你字符串A.B,每次操作可以将一段区间刷成任意字符,问最少需要几次操作可以使得字符串 ...

  6. 2017多校第6场 HDU 6096 String AC自动机

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6096 题意:给了一些模式串,然后再给出一些文本串的不想交的前后缀,问文本串在模式串的出现次数. 解法: ...

  7. HDU 6194 string string string(后缀数组+RMQ)

    string string string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. hdu 2476 String Painter

    第一道区间dp题,感觉题意不是很好理解 题意:一次可以转换某一个位置的字符,或是一串连续的字符,举第一个例子zzzzzfzzzzz 1:aaaaaaaaaaa 2: abbbbbbbbba 3: ab ...

  9. HDU 4821 String (HASH)

    题意:给你一串字符串s,再给你两个数字m l,问你s中可以分出多少个长度为m*l的子串,并且子串分成m个长度为l的串每个都不完全相同 首先使用BKDRHash方法把每个长度为l的子串预处理成一个数字, ...

随机推荐

  1. CodeForces 446A DZY Loves Sequences (DP+暴力)

    题意:给定一个序列,让你找出一个最长的序列,使得最多改其中的一个数,使其变成严格上升序列. 析:f[i] 表示以 i 结尾的最长上升长度,g[i] 表示以 i 为开始的最长上升长度,这两个很容易就求得 ...

  2. E20171121-sl

    contrast  n. 对比,对照; 差异; 对照物,对立面; [摄] 反差;

  3. bzoj 1724: [Usaco2006 Nov]Fence Repair 切割木板【堆】

    如果反着看,看成合并木板,就和合并果子一样了,把若干块放进一个小根堆,然后每次取出两个合并,把合并结果加进答案和堆里 代码里小根堆用优先队列实现(懒 #include<iostream> ...

  4. 清北考前刷题day7早安

  5. HDU 4135 容斥原理

    思路: 直接容斥 //By SiriusRen #include <cstdio> using namespace std; #define int long long ; int cas ...

  6. 洛谷 P3389 【模板】高斯消元法

    以下这个好像叫高斯约旦消元法,没有回代 https://www.luogu.org/blog/37781/solution-p3389 #include<cstdio> #include& ...

  7. Spring抽象JDBC,使用JdbcTemplate

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  8. hdu 4104 Discount

    http://acm.hdu.edu.cn/showproblem.php?pid=4104 一开始还以为这题是背包,然后优化下这个背包,但是一直都优化不出来. 然后题解是直接模拟而已,唉 先从小到大 ...

  9. TCPClient、TCPListener的用法

    支持Http.Tcp和Udp的类组成了TCP/IP三层模型(请求响应层.应用协议层.传输层)的中间层-应用协议层,该层的类比位于最底层的Socket类提供了更高层次的抽象,它们封装 TCP 和 UDP ...

  10. MVC之模型绑定

    1.前言 MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方 ...