HDU 4821 String 字符串hash】的更多相关文章

String Problem Description   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…
题意:给你一串字符串s,再给你两个数字m l,问你s中可以分出多少个长度为m*l的子串,并且子串分成m个长度为l的串每个都不完全相同 首先使用BKDRHash方法把每个长度为l的子串预处理成一个数字,接着根据题意直接map判重 BKDRHash:一种常用字符串hash,hash简单来说就是把一串字符串通过一些转化成为一个数字,并保证相同字符串转化的数字一样,不相同字符串转化的数字一定不一样.方法就是hash[i]=hash[i-1]*seed(进制)+str[i]-'a'+1(注意要加一,因为不…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4821 题目大意:给你M,L两个字母,问你给定字串里不含M个长度为L的两两相同的子串有多少个? 哈希+枚举 我就是不会枚举这样的,这次涨姿势了. 每次枚举起点,然后就能枚举全部的. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <alg…
题目链接https://vjudge.net/problem/HDU-4821 题意:给定字符串S ,询问用几个子串满足 : 1.长度为n*len  . 2. n个子串都不相同. 题解:倒序hash将S第i位的字符变成ull,利用map维护每个子串,遍历的时候只需要去掉开头小串然后加上后面一个小串就可以实现整个字符的遍历. Ac 代码: #include<algorithm> #include<iostream> #include<cstdio> #include<…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4821 字符串题. 现场使用字符串HASH乱搞的. 枚举开头! #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <queue> #include <map> #include <set> #inclu…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4622 题意:给定一个长度不超过2000的字符串,之后有不超过1e5次的区间查询,输出每次查询区间中不同的子串个数? 做法1:字符串hash 一般的做法就是模拟每段子串的长度L(从1到 len),这样时间复杂度为O(n^2);但是里面并没有计算子串比较是否相等以及存储的时间,而这段时间就是将字符串看成是“数字”,这样存储和比较的时间均降为O(1)了: 下面讲讲模板: 1.如何将字符串看成一个“高精度的…
String Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=95149#problem/I Description 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 o…
String 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 ha…
http://acm.hdu.edu.cn/showproblem.php?pid=4821 题意:给出一个字符串,现在问你可以找出多少个长度为M*L的子串,该子串被分成L个段,并且每个段的字符串都是不同的. 思路: 看BKDRHash看了半天,很神奇~.关于这个,大家可以看一下这篇博客http://blog.csdn.net/xu20082100226/article/details/52651072. 先计算出整个串的哈希值,套用公式$Hash[i]=Hash[i+1]*SEED+(ss[i…
哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助. 给你一部魔咒词典.当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能:当哈利需要某个功能但不知道该用什么魔咒时,你的程序要替他找到相应的魔咒.如果他要的魔咒不在词典中,就输出"what?" Input 首先列出词典中不超过100000条不同的魔咒词条,每条格式为: [魔咒] 对应功能 其中"…