POJ-1200(哈希)】的更多相关文章

Crazy Search Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32483   Accepted: 8947 Description Many people like to solve hard puzzles some of which may lead them to madness. One such puzzle could be finding a hidden prime number in a gi…
Many people like to solve hard puzzles some of which may lead them to madness. One such puzzle could be finding a hidden prime number in a given text. Such number could be the number of different substrings of a given size that exist in the text. As…
题目链接 Description Many people like to solve hard puzzles some of which may lead them to madness. One such puzzle could be finding a hidden prime number in a given text. Such number could be the number of different substrings of a given size that exist…
题目链接:http://poj.org/problem?id=1200 题意:给定一个字符串,字符串只有NC个不同的字符,问这个字符串所有长度为N的子串有多少个不相同. 思路:字符串HASH,因为只有NC个不同的字符,所以我们可以把字符串看成是一个NC进制的串,然后计算出字符串的前缀HASH.然后枚举起点判断子串的HASH值是否已经存在.因为有了前缀HASH值,所以转移是O(1)的. #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #in…
题目链接:http://poj.org/problem?id=1200 思路分析:从数据来看,该题目使用线性时间算法,可见子串的比较是不可能的:使用hash可以在常数时间内查找,可以常数时间内判重, 可以再线性时间内解决问题:问题关键在与Hash函数的选择,使得子串之间的Hash值不同:由于NC的提示,使用NC作为基数,其他字符 分配不同的数码,从1-NC,再求取Hash值,保证函数为单一映射: 代码如下: #include <stdio.h> #include <string.h>…
题目:http://poj.org/problem?id=1200 最近看了一个关于hash的问题,不是很明白,于是乎就找了些关于这方面的题目,这道题是一道简单的hash 字符串题目,就先从他入手吧. 题目说字串的最大数量不超过16Millions,也就是字串的存储16000000就够了. 查看网上给出的hash映射是把字串映射成为一个NC进制的数字每个字串都是一个数字. #include <stdio.h> #include <iostream> using namespace…
http://poj.org/problem?id=1200 #include<iostream> #include<cstring> using namespace std; const int maxn=2e7; ],ans=; ]; char s[maxn]; int main(){ memset(vis,,); scanf("%d%d%s",&len,&base,s); int base1=base; //把字符串转换为base进制的数…
第一次涉及HASH查找的知识 对于字符串的查找有很多前人开发出来的HASH函数,比较常用的好像是ELF 和 BKDR. 这道题没想到突破点是在于其nc值,告诉你组成字符串的字母种类. 还有用26进制,不管怎么说,只要避免产生冲突,怎么哈希都行. 用的是BKDRHash法. #include <iostream> #include <cstdio> #include <cstring> #define maxn 20000000 #define mm 1000000 us…
思路:利用Karp-Rabin算法的思想,对每个子串进行Hash,如果Hash值相等则认为这两个子串是相同的(事实上还需要做进一步检查),Karp-Rabin算法的Hash函数有多种形式,但思想都是把字符串映射成一个数字.本题hash函数是把字串转化为NC进制的数(实际上程序中计算结果已经被转换为10进制,因为NC进制数不同转化为10进制数自然不同,所以不影响判断结果),数组开到了1.6×10^7(我试了一下1.2×10^7也能AC),实际上这也是不严谨的,因为我们不能保证hash之后的数值在这…
https://vjudge.net/problem/POJ-1200 题意: 给出一个字符串,给出子串的长度n和给出的字符串中不同字符的个数nc,统计这个字符串一共有多少不同的长度为n的子串. 思路: 太菜了,还是看着题解做的.最开始根本不知道nc有何用...既然最多只有nc个不同的字符,那么就可以把每一个子串转化为一个nc进制的数,然后再把这个数转化为10进制数,之后统计一共有多少个不同的10进制数就可以了啊. 代码: #include <stdio.h> #include <str…