HDU1800 hash+去前导0
注意一:卡map的时间,但是好好写+运气还是可以卡过,哇。。。求人品爆发
注意二:去前导0,毕竟‘0’也有ASCII码
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
#define ULL unsigned long long
const int maxn=4007;
ULL V[maxn];
int Laxt[maxn],Next[maxn],To[maxn],Num[maxn],cnt;
int ans=0;
int seed=131;
int P=4001;
char c[40];
void _hash()
{
ULL now=0;int i;
int Len=strlen(c+1);
for(i=1;i<Len;i++) if(c[i]!='0') break;
for(;i<=Len;i++) now=now*seed+c[i];
int tmp=now%P;
for(i=Laxt[tmp];i;i=Next[i]){
if(V[i]==now){
Num[i]++;
ans=max(ans,Num[i]);
return ;
}
}
Next[++cnt]=Laxt[tmp];
Laxt[tmp]=cnt;
Num[cnt]=1;
ans=max(ans,Num[cnt]);
V[cnt]=now;
}
int main()
{
int i,j,n;
while(~scanf("%d",&n)){
memset(Laxt,0,sizeof(Laxt));
cnt=0;
ans=0;
for(i=1;i<=n;i++){
scanf("%s",c+1);
_hash();
}
printf("%d\n",ans);
}
return 0;
}
It is your time to fight!