zhoutb2333学习了哈希算法,他于是去统计给定一些字符串,其中有多少个本质不同的字符串。
但是zhoutb2333突发奇想,如果哈希采用的每次随机,那么结果会变成什么样呢?
辣鸡出题人又出锅了!subtask3的数据有问题,现在统一将模数改为65537
题目来源:zhoutb2333
他通过某种办法,获得了一个函数:int Rand(int x),它会等概率地返回一个 中的整数。
他写下了这样的代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int x=10,maxn=35,maxlen=16010;
ll HASH[maxn];
const ll p=65537;
char str[maxlen];
ll Hash(){
int base=Rand(x);
ll ret=0;
for(int i=1;str[i];i++)
ret=(ret*base+str[i]-'a'+1)%p;
return ret;
}
int main(){
int ans=0,n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%s",str+1),HASH[i]=Hash();
sort(HASH+1,HASH+n+1);
HASH[0]=-1;
for(int i=1;i<=n;i++)
ans+=(HASH[i]!=HASH[i-1]);
printf("%d\n",ans);
return 0;
}
zhoutb2333 想问你,给定一些字符串和参数 ,答案 的期望是多少呢?
是质数
参数 在这个程序中是确定的 ,但是每次输入会给定。