您的位置:首页 > 其它

HDU 1800 (哈希 水~)

2016-04-19 18:04 295 查看
题目链接:点击打开链接

题意:求某个数字最多出现多少次。

最简单的哈希。把前道0去掉。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
#define maxn 33
typedef unsigned long long ull;
#define seed 131
#define mod 131331

int n, ret;
char a[maxn], gg[maxn];
int cnt[mod];

#define hash Hash
void hash () {
int pos = 0;
int l = strlen (a);
while (a[pos] == '0' && pos < l-1)
pos++;
ull ans = 0;
for (; pos < l; pos++) {
ans = ans*seed + a[pos];
}
ans %= mod;
cnt[ans]++;
ret = max (ret, cnt[ans]);
return ;
}

int main () {
while (scanf ("%d", &n) == 1) {
ret = 0;
memset (cnt, 0, sizeof cnt);
for (int i = 1; i <= n; i++) {
scanf ("%s", a);
hash ();
}
printf ("%d\n", ret);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: