POJ 1200 Crazy Search 【hash】】的更多相关文章

<题目链接> 题目大意: 给定n,nc,和一个字符串,该字符串由nc种字符组成,现在要你寻找该字符串中长度为n的子字符串有多少种. 解题分析: 因为要判重,所以讲这些字符串hash一下,将不同的字符串映射为数字,这里我们是将该字符串转化为nc进制数,不同的字符串分别对应nc进制下不同的数. #include <cstdio> #include <cstring> using namespace std; ; char str[M]; bool hash[M]; ]; i…
RK法:https://www.cnblogs.com/16crow/p/6879988.html #include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include<iostream> #include<cstring> #include<set> #include<queue> #include<algorithm&…
题目链接: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…
第一次涉及HASH查找的知识 对于字符串的查找有很多前人开发出来的HASH函数,比较常用的好像是ELF 和 BKDR. 这道题没想到突破点是在于其nc值,告诉你组成字符串的字母种类. 还有用26进制,不管怎么说,只要避免产生冲突,怎么哈希都行. 用的是BKDRHash法. #include <iostream> #include <cstdio> #include <cstring> #define maxn 20000000 #define mm 1000000 us…
题目链接 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 #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进制的数…
思路:利用Karp-Rabin算法的思想,对每个子串进行Hash,如果Hash值相等则认为这两个子串是相同的(事实上还需要做进一步检查),Karp-Rabin算法的Hash函数有多种形式,但思想都是把字符串映射成一个数字.本题hash函数是把字串转化为NC进制的数(实际上程序中计算结果已经被转换为10进制,因为NC进制数不同转化为10进制数自然不同,所以不影响判断结果),数组开到了1.6×10^7(我试了一下1.2×10^7也能AC),实际上这也是不严谨的,因为我们不能保证hash之后的数值在这…
POJ图论分类[转] 一个很不错的图论分类,非常感谢原版的作者!!!在这里分享给大家,爱好图论的ACMer不寂寞了... (很抱歉没有找到此题集整理的原创作者,感谢知情的朋友给个原创链接) POJ:http://poj.org/ 1062* 昂贵的聘礼 枚举等级限制+dijkstra 1087* A Plug for UNIX 2分匹配 1094 Sorting It All Out floyd 或 拓扑 1112* Team Them Up! 2分图染色+DP 1125 Stockbroker…
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed…