单哈希 洛谷 3370
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef unsigned long long ULL;
const int MAXM = 1511;
const int MAXN = 10001;
int n, ans = 1;
char s[MAXM];
int a[MAXN];
ULL SEED = 131, MOD = 212370440130137957ll;//自然溢出
ULL getHash(char *h)
{
int len = strlen(s);
ULL hash = 0;
for (int i = 0; i < len; i++)
{
hash += (hash * SEED + (ULL)s[i]) % MOD;
}
return hash;
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%s", s);
a[i] = getHash(s);
}
sort(a + 1, a + n + 1);
for (int i = 1; i < n; i++)
{
if (a[i] != a[i + 1])
ans++;
}
printf("%d\n", ans);
return 0;
}