您的位置:首页 > 其它

POJ 1200 Hash

2016-07-16 22:19 302 查看

我的hash从来没写对过。。。。。。。。
(白学了快一年OI ……原来连个hash都没写对过)
但是
但是
今天是一个值得纪念的日子。

看看标题

我竟然在写hash的题解。
(好了好了 废话少说)
题意:
给你一个串,求长度为n的不同的子串的个数。
题目中的NC是什么意思 反正我没看懂,(But我能AC)
思路:
QY讲的hash 随便搞搞就过了。。。

// by SiriusRen
#include <bitset>
#include <cstdio>
#include <cstring>
using namespace std;
#define N 100000007
bitset<N>b;
long long nc,n,ans=0,len,q=0;
char a[700000];
int main(){
scanf("%lld%lld\n%s",&n,&nc,a);
len=strlen(a);
for(int i=0;i<=len-n;i++){
for(int j=0;j<n;j++)
q=((q<<8)+a[i+j])%N;
if(!b[q])b[q]=1,ans++;
q=0;
}
printf("%lld",ans);
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: