@[slehand](/user/1262697) 改成 ```ull``` 试试
by rsy_ @ 2024-01-21 01:39:08
双哈希
```c
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e5 +10;
ull base = 131;
char s[N];
int n;
ull mod1 = 19260817;
ull mod2 = 19660813;
struct node
{
ull x, y;
}a[N];
bool cmp(node a, node b)
{
return a.x < b.x;
}
ull hash1(char s[])
{
int len = strlen(s);
ull ans = 0;
for(int i = 0; i < len; ++i)
{
ans = (ans * base + (ull)s[i]) % mod1;
}
return ans;
}
ull hash2(char s[])
{
int len = strlen(s);
ull ans = 0;
for(int i = 0; i < len; ++i)
{
ans = (ans * base + (ull)s[i]) % mod2;
}
return ans;
}
int main()
{
int n;
while(~scanf("%d", &n))
{
for(int i = 1; i <= n; ++i)
{
scanf("%s", s);
a[i].x = hash1(s);
a[i].y = hash2(s);
}
sort(a + 1, a + n + 1, cmp);
int cnt = 1;
for(int i = 2; i <= n; ++i)
{
if(a[i - 1].x != a[i].x || a[i - 1].y != a[i].y)
{
cnt++;
}
}
cout<<cnt<<'\n';
}
return 0;
}
```
by timmyliao @ 2024-01-21 08:03:50
我说,用`set`不是更好吗
```cpp
#include <iostream>
#include <set>
using namespace std;
set <string> s;
int n;
string tmp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
for (int i=0; i<n; ++i){
cin >> tmp;
s.insert(tmp);
}
cout << s.size();
return 0;
}
```
by Mr_LiuXinan @ 2024-03-05 22:50:31