甚至被普及- 包超了(悲)
  • 板块灌水区
  • 楼主CZ_Yang
  • 当前回复22
  • 已保存回复22
  • 发布时间2024/8/15 10:29
  • 上次更新2024/8/15 10:50:57
查看原帖
甚至被普及- 包超了(悲)
1178154
CZ_Yang楼主2024/8/15 10:29

字符串哈希模板,调一下呗,这东西T我(悲

怎么会T呢(表疑惑

#include <bits/stdc++.h>
#define int long long
#define ull unsigned long long
using namespace std;
const int N = 1e5 + 100;
const ull P = 131;
ull F[N];
int n;

inline ull Hash (char s[]) {
	ull ans = 0, len = strlen(s);
	for (int i = 0 ; i < len; i ++) {
		ans = ans * P + (ull)s[i];
	}
	return ans;
}

inline int read (int &x) {
	x = 0;
	int f = 1;
	char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } 
	while (c >= '0' && c <='9') { x = x * 10 + c - 48; c = getchar(); }
	x *= f;
}

signed main() {
//	freopen ("P3370_1.in", "r", stdin);
	read (n);
	for (int i = 1; i <= n; i ++) {
		char s[10001];
		scanf ("%s", &s);
		F[i] = Hash(s);
	}
	sort (F + 1, F + 1 + n);
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		if (F[i] != F[i + 1]) {
			ans ++;
		}
	}
	printf ("%lld\n", ans);
	return 0;
}
2024/8/15 10:29
加载中...