POJ1200 Crazy Search
| Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description
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
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
of different substrings of size N found in the given text.
Sample Input
3 4
daababac
Sample Output
5
Hint
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的更多相关文章
- [poj1200]Crazy Search(hash)
Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26713 Accepted: 7449 Descrip ...
- POJ-1200 Crazy Search,人生第一道hash题!
Crazy Search 真是不容易啊,人生第一道hash题竟然是搜博客看题解来的. 题意:给你 ...
- POJ1200 A - Crazy Search(哈希)
A - Crazy Search Many people like to solve hard puzzles some of which may lead them to madness. One ...
- hdu 1381 Crazy Search
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1381 Crazy Search Description Many people like to sol ...
- (map string)Crazy Search hdu1381
Crazy Search Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1200:Crazy Search(哈希)
Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32483 Accepted: 8947 Des ...
- Crazy Search
poj1200:http://poj.org/problem?id=1200 题意:给你一个有m种字符串,求长度为n的连续子串由多少种. 题解:网上的代码都是hash,但是本人觉得hash有问题,就是 ...
- POJ 1200 Crazy Search (哈希)
题目链接 Description Many people like to solve hard puzzles some of which may lead them to madness. One ...
- Crazy Search POJ - 1200 (字符串哈希hash)
Many people like to solve hard puzzles some of which may lead them to madness. One such puzzle could ...
随机推荐
- 【JS】window.print打印指定内容
有时候网页用到打印但是不想打印所有内容,就需要只打印指定内容,下面简单演示下如何打印指定内容 1.在需要打印的指定内容的头部前面加“<!--startprint-->”,在尾部后面加上“& ...
- 22.1 高级函数【JavaScript高级程序设计第三版】
函数是JavaScript 中最有趣的部分之一.它们本质上是十分简单和过程化的,但也可以是非常复杂和动态的.一些额外的功能可以通过使用闭包来实现.此外,由于所有的函数都是对象,所以使用函数指针非常简单 ...
- scrapy之分布式
分布式爬虫 概念:多台机器上可以执行同一个爬虫程序,实现网站数据的分布爬取. 原生的scrapy是不可以实现分布式爬虫? a) 调度器无法共享 b) 管道无法共享 工具 scrapy-redis组件: ...
- POJ 3171 区间最小花费覆盖 (DP+线段树
Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4245 Accepted: 1429 D ...
- AD9 设置网络标号作用域
http://blog.sina.com.cn/s/blog_99c8ec600102uxul.html 1.版本:Altium Designer 10 2.原因:在进行多原理图设计时, 不同原理图之 ...
- Java 虚拟机结构分析
本博文主要介绍了JVM(Java Virtual Machine)的组成部分以及它们内部的工作机制和原理.需要注意的是,虽然平时我们用的大多是Sun(现已被Oracle收购)JDK提供的JVM,但是J ...
- git命令行操作详解
目录 1.常用操作 1.1 新建代码库 1.2 配置 1.3 remote管理 1.4 添加和撤销操作 1.5 代码提交 1.6 分支操作 1.7 查看信息 1.8 pull操作 1.9 push操作 ...
- +(void)load; +(void)initialize;有什么用处?
总得来说: 1.+load方法是在main函数之前调用的: 2.遵从先父类后子类,先本类后列类别的顺序调用: 3.类,父类与分类之间的调用是互不影响的.子类中不需要调用super方法,也不会调用父类的 ...
- IOS客户端的个人中心可以查看自己的博客了。
IOS客户端的个人中心可以查看自己的博客了. 写这篇是为了在客户端显示之用. 下一步实现在客户端发博客.
- 关于safaire下hash前面需要加/(正斜杠)
就是我们1.1框架是根据hash跳转的,今天我2.0跳转到1.1,pc一直测下来都是好的, 然后发现手机上一直跳转有问题,然后排查了半小时左右才发现 hash前面需要加/ 分割. 例如:http:/ ...