标签:scan display cad its spl def ash amp c++
目的:构造一个数字使之唯一代表一个字符串。
学习链接:https://www.luogu.org/blog/pks-LOVING/zi-fu-chuan-xue-xi-bi-ji-ha-xi-hash-yu-zi-dian-shu-trie#
自用模板:
P3370 【模板】字符串哈希:https://www.luogu.org/problemnew/show/P3370
#include<bits/stdc++.h> using namespace std; #define ull unsigned long long const int maxn=1e4+10; ull base=131,mod=21237044013013795711; int prime=233317; ull hashe(char *s) { int len=strlen(s); ull ans=0; for(int i=0;i<len;i++) { ans=(ans*base+(ull)s[i])%mod+prime; } return ans; } int main() { int n,ans=1; char s[maxn]; ull a[maxn]={0}; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%s",s); a[i]=hashe(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; }
标签:scan display cad its spl def ash amp c++
原文地址:https://www.cnblogs.com/myrtle/p/11546323.html