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

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 in the text. As you soon will discover, you really need the help of a computer and a good algorithm to solve such a puzzle.
Your task is to write a program that given the size, N, of
the substring, the number of different characters that may occur in the
text, NC, and the text itself, determines the number of different
substrings of size N that appear in the text.

As an example, consider N=3, NC=4 and the text
"daababac". The different substrings of size 3 that can be found in this
text are: "daa"; "aab"; "aba"; "bab"; "bac". Therefore, the answer
should be 5.

Input

The first line of input consists of two numbers, N and NC, separated by
exactly one space. This is followed by the text where the search takes
place. You may assume that the maximum number of substrings formed by
the possible set of characters does not exceed 16 Millions.

Output

The program should output just an integer corresponding to the number
of different substrings of size N found in the given text.

Sample Input

3 4
daababac

Sample Output

5

Hint

Huge input,scanf is recommended.

Source

RE到飞起,改了半天,标准代码比对无效。

然后发现数组开了160w……为什么我会把16 Millions理解错160w呢……

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n,nc;
int mp[],cnt;
char s[];
bool hash[];
int main(){
scanf("%d%d",&n,&nc);
scanf("%s",s);
int i,j;
int len=strlen(s)-;
for(i=;i<=len;i++)
if(!mp[s[i]])mp[s[i]]=++cnt;
int ans=;
for(i=;i<=len-n+;i++){
int hs=;
for(j=i;j<n+i;j++){
hs*=nc;
hs+=mp[s[j]];
}
if(!hash[hs])hash[hs]=,ans++;
}
printf("%d\n",ans);
return ;
}

POJ1200 Crazy Search的更多相关文章

  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 A - Crazy Search(哈希)

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

  4. hdu 1381 Crazy Search

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

  5. (map string)Crazy Search hdu1381

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

  6. POJ 1200:Crazy Search(哈希)

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

  7. Crazy Search

    poj1200:http://poj.org/problem?id=1200 题意:给你一个有m种字符串,求长度为n的连续子串由多少种. 题解:网上的代码都是hash,但是本人觉得hash有问题,就是 ...

  8. POJ 1200 Crazy Search (哈希)

    题目链接 Description Many people like to solve hard puzzles some of which may lead them to madness. One ...

  9. 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. POJ:3279-Fliptile(矩阵反转)

    Fliptile Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14701 Accepted: 5381 Description ...

  2. CONDENSE命令により、文字列から冗長スペースが削除

    CONDENSE 命令により.文字列から冗長スペースが削除されます. CONDENSE c [NO-GAPS]. この命令により.項目 c に先行空白が含まれる場合は削除され.その他の空白列がある場合 ...

  3. Javascript Step by Step - 04

    前言 本篇主要讨论jQuery的常用的若干操作.为了能直观的显示操作的结果,首先建立一个html文件,内容如下: <!DOCTYPE html> <html> <head ...

  4. Javascript Step by Step - 03

    前言 ajax 即“Asynchronous JavaScript and XML”(异步的JavaScript和XML).现在这个词的覆盖面有所扩展,把允许浏览器与服务器通信而无需刷新当前页面的技术 ...

  5. 初学JS——利用JS制作的别踩白块儿(街机模式) 小游戏

    这个是上个星期5写的了,当时是突然想写个游戏,就想到了别踩白块儿,当时的想法是 可能普通模式的别踩白块儿因为他的“块儿”是滚动的向上这种,以我目前会的技术想不出怎么写, 但是如果是街机模式,通过你每按 ...

  6. 二分法求函数值的Pascal实现

    用二分法求在(a,b)上单调的函数近似值   第八行的表达式可更改,第三行的kexi决定的精度,小数值计算可将第五行的extended更为real或double PROGRAM EQUANTION ( ...

  7. SQL Server 分组取 Top 笔记(row_number + over 实现)

    先看SQL语句(注意:这是在SQL Server 2005+ [包括2005] 的版本才支持的哦,o(∩_∩)o 哈哈~) SELECT col1,col2,col3 FROM table1 AS a ...

  8. 抓包工具 - Fiddler - (二)

    <转载自 miantest> 在上一篇中介绍了Fiddler的基本使用方法.通过上一篇的操作我们可以直接抓取浏览器的数据包.但在APP测试中,我们需要抓取手机APP上的数据包,应该怎么操作 ...

  9. 【视觉SLAM14讲】ch3课后题答案

    1.验证旋转矩阵是正交矩阵 感觉下面这篇博客写的不错 http://www.cnblogs.com/caster99/p/4703033.html 总结一下:旋转矩阵是一个完美的矩阵——正交矩阵.①行 ...

  10. 【转】mysql 计划事件

    转自:http://www.cnblogs.com/c840136/articles/2388512.html MySQL5.1.x版本中引入了一项新特性EVENT,顾名思义就是事件.定时任务机制,在 ...