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 ...
随机推荐
- P1067 试密码
P1067 试密码 转跳点:
- Centos7关闭防火墙 设置开机启动
[root@nmserver-7 ~]# systemctl stop firewalld.service [root@nmserver-7 ~]# systemctl status firewall ...
- Java虚拟机05.2(内存分配)
jdk1.7中堆内存分为:年轻代+老年代+永久代.但是永久代有作为非堆内存存在,也就是说堆内存的大小应该为年轻代+老年代.在tomcat容器中,如果jsp页面过多可能出现永久代溢出.通常栈溢出都是程序 ...
- [Codeforces]1263E Editor
The development of a text editor is a hard problem. You need to implement an extra module for bracke ...
- 056、Java中continue的用法
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- H5页面,百度地图点击事件
需求:用户点击地图的时候获取地址街道,编码等详细信息. 然后看百度API文档,看到了click事件,关键时候还是需要看文档的. 实现 这样子虽然在浏览器的手机模拟器下是没有问题的 但是放在机器上测试的 ...
- dedecms 栏目目录用首字母生成的方法
修改dede/catalog.add.php文件 85行 $toptypedir = GetPinyin(stripslashes($toptypename)); 修改为 $toptypedir = ...
- Linux: 桥接 NET HOST-only
桥接 虚拟机会利用真实的网卡和真实计算机之间通信 还能和同一局域网之间的计算机之间通信 缺点:会耗费一个ip地址 NET:虚拟机会通过VMnet8 虚拟的网卡与真实计算机之间通信 如果真实计可 ...
- redis.conf文件配置
最重要三个配置 1. bind 127.0.0.1 需要注释掉这一行,使别的主机可以访问 2. daemonize no 需要改为yes,使其后台运行 3. requirepass foobared ...
- asp.net mvc邮箱激活
1.发送邮件 public ActionResult SendEmail() { var member = dbSession.MemberRepository.LoadEntities(p => ...