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;
}
题意:求某个数字最多出现多少次。
最简单的哈希。把前道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;
}
相关文章推荐
- 内存区域的划分和分配
- C#学习笔记二: C#类型详解
- Android 6.0 运行时权限处理
- Unity3D Terrain Settings 彻底搞懂 地形详细设置 全实验与解析 (一)Pixel Error
- codevs 1009 产生数 2002年NOIP全国联赛普及组
- iOS之应用程序启动过程及原理总结
- java中long值表达式需要注意的一种情况
- JS生成某个范围的随机数(四种情况)
- windbg 常用命令详解
- 游戏数据库设计 参考博客
- 请求和响应信息详解
- Android 个人学习笔记之---SAX解析XML文件
- 二叉树的所有路径
- (学习进度表)【第八周】
- JQuery之append和appendTo的区别,还有js中的appendChild用法
- 关于C++中的友元函数的总结
- libusb学习一
- Linux学习总结(4)——Centos6.5使用yum安装mysql——快速上手必备
- Linux学习总结(4)——Centos6.5使用yum安装mysql——快速上手必备
- mongodb部署单节点(一)