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 ...
随机推荐
- html ajax请求 php 下拉 加载更多数据 (也可点击按钮加载更多)
<input type="hidden" class="total_num" id="total" value="{$tot ...
- POJ 2441 状压DP
Arrange the Bulls Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 5289 Accepted: 2033 ...
- c++ 计算器 带括号 代码实现
我用了两个栈 一个用来存数字 一个用来存运算符 这里引入优先度的概念便于理解 不同的运算符有不同的优先度 当优先度高的符号进入栈中 所有比它优先度低的符号都要弹出 对 就是这么霸道 ( 没有优先度 没 ...
- 代理缓存服务之Squid
代理缓存服务 Squid是linux系统中最为流行的一款高性能代理服务软件,通常用作Web网站的前置缓存服务,能够代替用户向网站服务器请求页面数据并进行缓存. 简单来说,Squid服务程序会按照收到的 ...
- Android快速发布项目到jcenter详解
不管别人的教程多详细,都有他们忽略的坑,所以,都要自己动手.我也是参考了许多许多的博客,弄了一上午加下午十分钟,才搞定. 参考: 下面这个是大部分的步骤 http://blog.csdn.net/zh ...
- pdo事务
$pdo->beginTransaction() $pdo->commit() $pdo->rollback();
- nodejs基础1
nodejs学习网站: https://github.com/alsotang/node-lessons 1.全局对象 (1)node中没有window对象,有global对象替代window对象 g ...
- 简洁好看的form样式收藏
本文转载自 http://www.laozuo.org/3495.html 为了方便自己查阅所以搬运过来,如有侵权希望原作者联系我删除不要突然去法院告我呀! 颜色样式啥的都可以根据需求自己调整的,这些 ...
- Jenkins拾遗--第二篇(初步配置Jenkins)
插件配置 第一次安装Jenkins的时候会让你配置插件.这里有一个建议:就是把所有插件都看一遍,如果用不到,就不要勾选.Jenkins插件兼容性有的时候不是很好,多装多出事儿,保持最小集就好.浏览一遍 ...
- Pascal “熊猫烧香”(骗人的)
Pascal仿熊猫烧香病毒,慎用 program japussy;useswindows, sysutils, classes, graphics, shellapi{, registry};cons ...