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. php 删除指定扩展名文件

    <?php /** *@param $path文件夹绝对路径 $file_type待删除文件的后缀名 *return void */ function clearn_file($path, $f ...

  2. JavaSE 第二次学习随笔(作业一)

    package homework2; import java.io.ObjectInputStream.GetField; import java.util.Arrays; public class ...

  3. Android 使用Retrofit2.0+OkHttp3.0实现缓存处理+Cookie持久化第三方库

    1.Retrofit+OkHttp的缓存机制 1.1.第一点 在响应请求之后在 data/data/<包名>/cache 下建立一个response 文件夹,保存缓存数据. 1.2.第二点 ...

  4. startActivityForResult 请求码不正确

    今天遇到一个坑,就是 startActivityForResult 接收不到正确的请求码. 比如,我startActivityForResult的时候,设置的请求码是4,但是接收到的时候是100032 ...

  5. laravel5.5路由

    目录 1. routes/web.php 2. routes/api.php 3. 重定向路由 4. 路由参数 5. 约束 6. 命名路由 7. 路由组 8 路由模型绑定 9 表单方法伪造 10 访问 ...

  6. 树莓派网线连接后通过ssh远程连接

    新安装的树莓派默认是不支持ssh远程连接的,通过PuTTY (64-bit)会提示连接被拒绝. 本文支持笔记本或pc直接通过网线连接树莓派,具体操作步骤如下: 一.确定树莓派的ip地址及是否开启ssh ...

  7. CentOS7配置图形界面及设置vnc远程连接、windows远程桌面连接

    安装CentOS桌面 yum groupinstall "GNOME Desktop" 重启,进入终端,将启动模式变更为图形模式 systemctl set-default gra ...

  8. Lazarus教程 中文版后续给出

    市面上有介绍Delphi的书籍(近来Delphi的书也是越来越少了),但没有一本系统的介绍Lazarus的书,这本书是网上的仅有的一本Lazarus教程,目前全部是英文,不过我已经着手开始翻译,争取尽 ...

  9. 【Substring with Concatenation of All Words】cpp

    题目: You are given a string, s, and a list of words, words, that are all of the same length. Find all ...

  10. day-python入门3

    本节内容 鸡汤.电影 IDE介绍 知识回顾 数据类型 For循环 while循环 列表及常用操作 IDE介绍   IDE即集成开发环境        常见IDE   Visualstudio  : w ...