如题,原来写字符串哈希的时候用了srand()
不知道CCF的评测机 允不允许用/能不能实现
#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<=b;i++)
#define Shion cout <<'\n'<<"Shion is too poor to print that."
const signed Miku=0x3f3f3f3f;
const signed N=1e4+50;
using namespace std;
#define ull unsigned long long
int n,ans=1;
string in;
int mod1=1e9+7,mod2=1e9+9,base;
struct saving{
ull a,b;
}sav[10010];
ull hashCalc(string s,bool op){
int len=s.length();
ull ans=0;
f(i,0,len-1)
if(op)
ans=(ans*base+s[i])%mod1;
else
ans=(ans*base+s[i])%mod2;
return ans;
}
bool cmp(saving a,saving b){
return a.a<b.a;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0);
srand(time(0));
base=rand()%200+50;
mod1+=rand()%50;
mod2+=rand()%50;
cin>>n;
f(i,1,n){
cin>>in;
sav[i].a=hashCalc(in,0);
sav[i].b=hashCalc(in,1);
}
sort(sav+1,sav+n+1,cmp);
f(i,2,n)
if(sav[i].a!=sav[i-1].a&&sav[i].b!=sav[i-1].b)
ans++;
cout<<ans;
return 0;
Shion;
}