#include<cstdio>
#include<cstring>
#define max 3007
int n,am[max],ans,hash[max];
inline int ELFhash(char *str)
{
int h = 0,k;
while(*str)
{
h = (h<<4) + *str++;
k = h&0xf0000000L;
if(k){
h^=(k>>24);
h&~k;
}
}
return h;
}//ELFhash
inline void HashIt(char *str)
{
while(*str=='0')str++;
int k = ELFhash(str);
int t = k%max;
while( hash[t] != k && hash[t] != -1 )
{
t = (t+7)%max;
}
if(hash[t]==-1){
hash[t] = k;
am[t] = 1;
if(1>ans)ans = 1;
}
else{
am[t]++;
if(am[t]>ans)ans = am[t];
}
}
int main()
{
char s[100];
while(scanf("%d",&n)!=EOF)
{
memset(am,0,sizeof(am));
memset(hash,-1,sizeof(hash));
ans = -1;
while(n--)
{
scanf("%s",s);
HashIt(s);
}
printf("%d\n",ans);
}
return 0;
}
hdoj-1800-Flying to the Mars ELFhash模板
最新推荐文章于 2017-11-08 20:15:16 发布