# hdu1800 Flying to the Mars ELFHash/BKDHash

409人阅读 评论(0)

we assume that one soldier has one level number indicating his degree. The soldier who has a higher level could teach the lower , that is to say the former’s level > the latter’s . But the lower can’t teach the higher. One soldier can have only one teacher at most , certainly , having no teacher is also legal. Similarly one soldier can have only one student at most while having no student is also possible. Teacher can teach his student on the same broomstick .Certainly , all the soldier must have practiced on the broomstick before they fly to the Mars! Magic broomstick is expensive !So , can you help PPF to calculate the minimum number of the broomstick needed .

#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define maxn 2000003
using namespace std;
int hash[3003];
int Count[3003];
int ans,n;
int BKDHash(char *key)
{
unsigned int hash=0;
unsigned int seed=131;
while(*key)
{
hash=hash*seed+*key++;
}
return (hash&0x7FFFFFFF);
}
/*
ELFhash函数是对字符串的散列。

ELFhash函数对于能够比较均匀地把字符串分布在散列表中。
*/
int ELFHash(char *key)
{
unsigned int hash=0;
unsigned int seed=0;
while(*key)
{
hash=(hash<<4)+*key++;
if((seed=hash&0xf0000000L)!=0)
{
hash^=  seed>>24;
}
hash&=~seed;
}
return hash;
}
void hashit(char *c)
{
int k,t;
while(*c=='0')
{
c++;
}
k=BKDHash(c);
t=k%3003;
while(hash[t]!=k&&hash[t]!=-1)
{
t=(t+10)%3003;
}
if(hash[t]==-1)
{
hash[t]=k;
Count[t]=1;
}
else if(++Count[t]>ans)
ans=Count[t];
}
int main()
{

char c[30];
while(cin>>n)
{
ans=1;
memset(hash,-1,sizeof(hash));
for(gets(c);n>0;n--)
{
gets(c);
hashit(c);
}
cout<<ans<<endl;
}
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：48003次
• 积分：1309
• 等级：
• 排名：千里之外
• 原创：86篇
• 转载：7篇
• 译文：0篇
• 评论：6条
最新评论