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

  1. 3 3
  2. abcabcbcaabc

Sample Output

  1. 2

Source

 
解题:字符串hash+map
 
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <climits>
  7. #include <vector>
  8. #include <queue>
  9. #include <cstdlib>
  10. #include <string>
  11. #include <set>
  12. #include <stack>
  13. #include <map>
  14. #define LL long long
  15. #define ULL unsigned long long
  16. #define pii pair<int,int>
  17. #define INF 0x3f3f3f3f
  18. #define seek 131
  19. using namespace std;
  20. const int maxn = ;
  21. map<ULL,int>mp;
  22. char str[maxn];
  23. ULL base[maxn],hs[maxn];
  24. int main() {
  25. int M,L,len,i,j,ans;
  26. ULL tmp;
  27. base[] = ;
  28. for(i = ; i < maxn; i++) base[i] = base[i-]*seek;
  29. while(~scanf("%d%d%s",&M,&L,str)){
  30. len = strlen(str);
  31. ans = ;
  32. hs[len] = ;
  33. for(i = len-; i >= ; i--)
  34. hs[i] = hs[i+]*seek+str[i]-'a';
  35. for(i = ; i < L && i + M*L <= len; i++){
  36. mp.clear();
  37. for(j = i; j < i+M*L; j += L){
  38. tmp = hs[j] - hs[j+L]*base[L];
  39. mp[tmp]++;
  40. }
  41. if(mp.size() == M) ans++;
  42. for(j = i+M*L; j+L <= len; j += L){
  43. tmp = hs[j-M*L] - hs[j-M*L+L]*base[L];
  44. mp[tmp]--;
  45. if(!mp[tmp]) mp.erase(tmp);
  46. tmp = hs[j] - hs[j+L]*base[L];
  47. mp[tmp]++;
  48. if(mp.size() == M) ans++;
  49. }
  50. }
  51. printf("%d\n",ans);
  52. }
  53. return ;
  54. }

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. 清北考前刷题day5早安

    /* C(n,k) */ #include<iostream> #include<cstdio> #include<cstring> #define ll long ...

  2. No task executor bean found for async processing: no bean of type TaskExecut

    使用springcloud,添加异步方法后,调用异步成功,但有个 No task executor bean found for async processing: no bean of type T ...

  3. HDU 1879(最小生成树)

    #include "iostream" #include "algorithm" #include "cstdio" using names ...

  4. CF17C Balance

    题意 [题目描述] 一个仅由a,b,c三种字符组成的字符串,可以对其进行如下两种操作: 选择两个相邻字符,将第一个字符替换成第二个. 选择两个相邻字符,将第二个字符替换成第一个. 这样,通过任意多次的 ...

  5. 贪心 HDOJ 5355 Cake

    好的,数据加强了,wa了 题目传送门 /* 题意:1到n分成m组,每组和相等 贪心:先判断明显不符合的情况,否则肯定有解(可能数据弱?).贪心的思路是按照当前的最大值来取 如果最大值大于所需要的数字, ...

  6. datagrid上面的查询按钮设置了,但是分页工具栏不显示

    原因:查询的linkbutton没有放在toolbar里. <script type="text/javascript"> $(function(){ $('#dg') ...

  7. MySQL的主从复制(windows)

    在我们实际的开发中,当系统业务到达一定的程度,可能数据库会到达一定的瓶颈,但实际开发中最容易到达数据库瓶颈的应该是数据库的读性能,一般的业务大多都是读多写少,我们可以通过提高读的性能来提高数据库的整体 ...

  8. 如何取消android studio启动时自动打开上次关闭的项目

    Androidstudio默认每次android studio启动就会自动打开上次关闭的项目,如果想要取消并让它显示此界面 只需要  

  9. MFC_1.2 消息映射宏 数据绑定和交换

    消息映射宏 有三个主要的宏 类内声明 DECLARE_MESSAGE_MAP 表示使用消息映射 在CPP文件中使用 BEGIN_MESSAGE_MAP 和 END_MESSAGE_MAP 包含对应的消 ...

  10. JSON字符串的生成

    public class Corporation { public string remark { get; set; } public string version { get; set; } pu ...