由于已经给出字符只有NC种,故可以把子串视为一个NC进制的数,以此构造hash函数就可以了

 #include <set>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=;
char s[MAXN];int hash[MAXN],num[];
int main(){
for(int N,NC;scanf("%d%d",&N,&NC)!=EOF;){
memset(hash,,sizeof(hash));
memset(num,,sizeof(num));
scanf("%s",s+);
int cnt=,ans=,len=strlen(s+);
for(int i=;i<=len&&cnt<=NC;i++)if(!num[s[i]])num[s[i]]=cnt++;
for(int i=;i<=len-N+;i++){
int hashi=;for(int j=i;j<=i+N-;j++)hashi=hashi*NC+num[s[j]];
hash[hashi]?:ans++,hash[hashi]=;
}
cout<<ans<<endl;
}
return ;
}

C++-POJ1200-Crazy Search[hash]的更多相关文章

  1. [poj1200]Crazy Search(hash)

    Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26713 Accepted: 7449 Descrip ...

  2. POJ-1200 Crazy Search,人生第一道hash题!

                                                        Crazy Search 真是不容易啊,人生第一道hash题竟然是搜博客看题解来的. 题意:给你 ...

  3. POJ1200 Crazy Search

    Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description Many peo ...

  4. poj 1200 Crazy Search(hash)

    题目链接:http://poj.org/problem?id=1200 思路分析:从数据来看,该题目使用线性时间算法,可见子串的比较是不可能的:使用hash可以在常数时间内查找,可以常数时间内判重, ...

  5. hdu1381 Crazy Search(hash map)

    题目意思: 给出一个字符串和字串的长度,求出该字符串的全部给定长度的字串的个数(不同样). 题目分析: 此题为简单的字符串哈hash map问题,能够直接调用STL里的map类. map<str ...

  6. POJ1200 A - Crazy Search(哈希)

    A - Crazy Search Many people like to solve hard puzzles some of which may lead them to madness. One ...

  7. hdu 1381 Crazy Search

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1381 Crazy Search Description Many people like to sol ...

  8. (map string)Crazy Search hdu1381

    Crazy Search Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. POJ 1200:Crazy Search(哈希)

    Crazy Search Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32483   Accepted: 8947 Des ...

  10. Crazy Search POJ - 1200 (字符串哈希hash)

    Many people like to solve hard puzzles some of which may lead them to madness. One such puzzle could ...

随机推荐

  1. win下的终端使用指南

    win下的终端使用指南 win 下的命令行工具是真的难用 . 具体的难用就不形容了 . 有了 PowerShell 也没觉得好用 . 还是喜欢Linux的终端,及Bash命令. 替换方案 比较好的替换 ...

  2. Android电源管理基础知识整理

    前言 待机.睡眠与休眠的区别? Android开发者官网当中提到"idle states",该如何理解,这个状态会对设备及我们的程序造成何种影响? 进入Doze模式中的idle状态 ...

  3. youhua

  4. IDEA 和 Webstorm JAR包方式破解

    IDEA 和 Webstorm JAR包方式破解 IDEA 我是用的IDEA版本是 18.3,更新版本的IDEA很多激活码都不能用了,或者不好激活了. 首先下载相应的 软件版本 和破解 jar包. 下 ...

  5. python3练习100题——044

    41-43讲关于python的变量范围,没有什么别的内容,我删除了. 原题链接:http://www.runoob.com/python/python-exercise-example44.html ...

  6. C++ lambda函数及其用法(转)

    由于接触C++不久,很多东西比较陌生,今天看阿里云OSS的C++ SDK文件下载部分例子,发现有如下lambda表达式用法,故了解一下相关知识 /*获取文件到本地文件*/ GetObjectReque ...

  7. 【巨杉数据库SequoiaDB】助力金融科技升级,巨杉数据库闪耀金融展

    11月4日,以“科技助创新 开放促改革 发展惠民生”为主题的2019中国国际金融展和深圳国际金融博览会在深圳会展中心盛大开幕. 中国人民银行党委委员.副行长范一飞,深圳市人民政府副市长.党组成员艾学峰 ...

  8. easyui-numberbox后台获取数据后,鼠标一点击就自动清空了

    <input type="text" name="txtMeterInitData" id="txtMeterInitData" cl ...

  9. Subway POJ - 2502 spfa

    #include<cstdio> #include<cmath> #include<cstring> #include<cstring> #includ ...

  10. vue中jquery详情

    jQuery基本语法 $(selector).action() 基本选择器:$("#id") 标签选择器:$("tagName") class选择器:$(&qu ...