看前请参考:
https://studyingfather.com/archives/841(只看个大概)
https://www.luogu.com.cn/problem/P3370
https://www.luogu.com.cn/problem/solution/P3370
https://www.cnblogs.com/moyujiang/p/11213535.html
利益相关(单Hash撞不出来的勇士们)
(双hash,但是出错了的勇士们)
解决方案:
请用双hash(单hash就连老题解都是卡的)
请用sting(亲测,不要抱着老C不放了同志们)
学习通道(b站搜ACM 北理工STL集训 照着找文档写一遍!!!!)
#include <iostream>
#include<string>
#include<map>
#include<utility>
#define N 1001
#define inf 1<<31
using namespace std;
map<pair<int, int>,bool> vals;
int base1=131;
int base2=127;
const int mod1=1<<31;
const int mod2=1<<31-1;
inline pair<int,int> hashe(string s){
int len=s.size();
int hash1=0,hash2=0;
for(int i=0; i<len; i++)
{
hash1=(hash1*base1+s[i]-'0')%mod1;
hash2=(hash2*base2+s[i]-'0')%mod2;
}
return make_pair(hash1,hash2);
}
int main()
{
int n, ans=0;
cin>>n;
for(int i=1; i<=n; i++)
{
string s;
cin>>s;
pair<int, int> val;
val=hashe(s);
if(vals[val])ans++;
else vals[val]=1;
}
ans=n-ans;
printf("%d\n",ans);
system("pause");
return 0;
}