POJ1200 A - Crazy Search(哈希)
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
Output
Sample Input
3 4
daababac
Sample Output
5
Hint
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn=;
ll hash[maxn],num[];
char s[maxn];
int main()
{
ll n,m;
while(~scanf("%lld%lld%s",&n,&m,s))
{
// memset(hash,0,sizeof(hash));
// memset(num,0,sizeof(num));
ll len=strlen(s);
ll cnt=;
num[s[]]=cnt++;
for(int i=;i<len;i++)
{
if(num[s[i]]==)
num[s[i]]=cnt++;
}
ll ans=;
for(int i=;i<=len-n;i++)
{
ll sum=;
for(int j=;j<n;j++)
{
sum=sum*m+num[s[i+j]];
// printf("%lld * %lld+%lld ",sum,m,num[s[i+j]]);
}
if(!hash[sum])
{
ans++;
// printf("hash[sum]:%lld sum:%lld \n",hash[sum],sum);
hash[sum]=;
}
}
printf("%lld\n",ans);
}
return ;
}
POJ1200 A - Crazy Search(哈希)的更多相关文章
- [poj1200]Crazy Search(hash)
Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26713 Accepted: 7449 Descrip ...
- POJ 1200:Crazy Search(哈希)
Crazy Search Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32483 Accepted: 8947 Des ...
- POJ-1200 Crazy Search,人生第一道hash题!
Crazy Search 真是不容易啊,人生第一道hash题竟然是搜博客看题解来的. 题意:给你 ...
- poj1200Crazy Search (哈希)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Crazy Search Time Limit: 1000MS Memory ...
- 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 ...
- Crazy Search POJ - 1200 (字符串哈希hash)
Many people like to solve hard puzzles some of which may lead them to madness. One such puzzle could ...
- POJ 1200 Crazy Search (哈希)
题目链接 Description Many people like to solve hard puzzles some of which may lead them to madness. One ...
- POJ1200 Crazy Search
Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Description Many peo ...
随机推荐
- html css3
一.引入样式 1.行内样式表 <h1 style="color: red;font-size: 18px;">10-30</h1> 2.内部样式表(在hea ...
- NO30 磁盘分区--Raid--ext2文件系统
Raid: ext2文件系统:
- webpack 命令 Module build failed (from ./node_modules/babel-loader/lib/index.js) 错误问题解决方案
在项目中运行的时候出现报错,错误为Module build failed (from ./node_modules/babel-loader/lib/index.js) 解决方案: 控制台输入 np ...
- Koa微信公众号开发
微信开发者模式开启需要服务器域名合法并且把接口配置好,这个接口是接通的关键,接通后微信后台的菜单设置功能,客服功能会失效,需要开发者自定义菜单和智能客服界面,并且接通后可以调用微信网页内部的定位分享等 ...
- JAVA Random 详解
Java中存在着两种Random函数: 一.java.lang.Math.Random; 调用这个Math.Random()函数能够返回带正号的double值,该值大于等于0.0且小于1.0,即取值范 ...
- tornado peewee_async
https://peewee-async.readthedocs.io/en/latest/peewee_async/examples.html https://www.cnblogs.com/Vic ...
- 电脑必须用U盘引导盘才能进系统解决办法
昨天为了装Ubuntu双系统把系统给装崩了,结果重装win7系统之后出现了以下问题,百度的结果有些杂乱,解决过程自己做一下记录. 问题一:安装程序结束后,出现“Windows安装程序无法将Window ...
- C#与unity中base64string和图片互转
C#: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- 官网英文版学习——RabbitMQ学习笔记(五)Publish/Subscribe
发布/订阅模式:把一个消息发送给多个消费者. 前几篇文章的思想是,我们好像看到了生产者将消息直接发送给queue,然后消费者也从queue中进行消费.其实并非如此,RabbitMQ中的消息传递模型的核 ...
- USB Windows驱动 音频解决方案芯片DP108
DP108是一款完全替代CM108的高度集成的单芯片USB音频解决方案芯片.方便的USB即插即用的兼容性,用户可以快速创建易用性,高质量和便携式USB音频产品基于高度集成的单芯片解决方案.所有重要的模 ...