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. Laravel操作上传文件的方法

    1.获取上传的文件 $file=$request->file('file');2.获取上传文件的文件名(带后缀,如abc.png) $filename=$file->getClientOr ...

  2. python——获取数据类型

    在python中,可使用type()和isinstance()内置函数获取数据类型 如: (1)type()的使用方法: >>> a = '230'         >> ...

  3. 理解JAVA与C的运行机制

    1.java的运行机制 java的编译过程,将java的源程序(扩展名为.java的文件),由java编译程序将java的字节码文件(.class文件)在jvm上运行,机器码有cpu运行, jvm编译 ...

  4. Git Cheatshell - Pro Git

    A git cheatshell based on the book: http://www.git-scm.com/book/en/v2. Repository Configuration git ...

  5. nodejs安装&bower 安装

    1.进入官网下载:https://nodejs.org/en/ 2.直接进行安装,可以将安装路径设置为:D:\nodejs 3.进入node.js command prompt 命令窗口 4.检测是否 ...

  6. CentOS 7.X 防火墙简单配置

    CentOS7使用的是Linux Kernel 3.10.0的内核版本,新版的Kernel内核已经有了防火墙netfilter,并且使用效能更高,稳定性更好. 配置防火墙的两种方法: 一.使用xml配 ...

  7. day06_05 字典

    1.0 字典 1.1 补充知识:用id可以查找出变量的内存地址 a = 10 print(id(a)) #找出内存地址 #>>>506528496 b = 15 print(id(b ...

  8. windows auto activate

    目前所支持的windows镜像都是未激活状态,未激活状态下很多功能无法使用. 以后将要实现的功能是,windows虚机启动后,网络正常后能与KMS服务器通信,自动激活key 目前想到两种办法: 1.b ...

  9. HDU 4109 Instrction Arrangement(DAG上的最长路)

    把点编号改成1-N,加一点0,从0点到之前任意入度为0的点之间连一条边权为0的边,求0点到所有点的最长路. SPFA模板留底用 #include <cstdio> #include < ...

  10. maven学习(十六)——使用Maven构建多模块项目

    在平时的Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,最常见的就是分为domain(域模型层).dao(数据库访问层).service(业务逻辑层).web(表现层),这样分层之 ...