# hdu1800 Flying to the Mars ELFHash/BKDHash

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;
}
}


• 本文已收录于以下专栏：

## hdu1800Flying to the Mars

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe...

## HDU 1800 Flying to the Mars (哈希表)

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe...

## HDU-OJ-1800 Flying to the Mars

Flying to the MarsTime Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others...

## HDU 1800 Flying to the Mars 字符串哈希||字典树||map

• s_h_r
• 2015年06月17日 16:13
• 327

## HDU 1800 Flying to the Mars(trie)

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe...

## hdu 1800 Flying to the Mars(贪心)

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe...

## Flying to the Mars HDU1800 map 简单水题

Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other...
• wr132
• 2015年01月31日 21:37
• 396

## hdu 1800 Flying to the Mars(字典树统计)

举报原因： 您举报文章：hdu1800 Flying to the Mars ELFHash/BKDHash 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)