poj3274 hash数组
来源:互联网 发布:vb向下取整函数 编辑:程序博客网 时间:2024/05/01 12:00
#include <iostream>#include <cstdio>#include <cstring>#define N 100001#define Prime 99983using namespace std;int n, k, flag[N][31], c[N][31], hash[Prime];inline int hashcode(const int *v){ int s = 0; for(int i = 0; i < k; i++) s=((s << 2) + (v[i] >> 4)) ^ (v[i] << 10); s = s % Prime; s = s < 0 ? s + Prime : s; return s;}int main(){ int i, j, tmp, maximum = 0; scanf("%d%d", &n, &k); memset(flag, 0, sizeof(flag)); memset(c, 0, sizeof(c)); memset(hash, -1, sizeof(hash)); hash[hashcode(c[1])] = 0; for (i = 1; i <= n; i++) { scanf("%d", &tmp); for (j = 0; j < k; j++) { if ((tmp >> j) & 1) flag[i][j] = flag[i - 1][j] + 1; else flag[i][j] = flag[i - 1][j]; c[i][j] = flag[i][j] - flag[i][0]; } tmp = hashcode(c[i]); while (hash[tmp] != -1) { for (j = 1; j < k; j++) if (c[i][j] != c[hash[tmp]][j]) break; if (j >= k) { j = i - hash[tmp]; maximum = maximum > j ? maximum : j; break; } tmp++; } if (hash[tmp] == -1) hash[tmp] = i; } printf("%d\n", maximum); return 0;}
0 0
- poj3274 hash数组
- poj3274 hash
- poj3274 hash
- poj3274数位HASH
- poj3274(数字hash)
- poj3274--Gold Balanced Lineup(hash)
- poj3274数组的哈希
- POJ3274-牛的属性-HASH-ACM
- POJ3274 -Gold Balanced Lineup- HASH+前缀和
- POJ3274
- poj3274
- poj3274
- poj3274
- poj3274
- poj3274
- POJ3274
- poj3274
- POJ3274 Gold Balanced Lineup 数组的哈希
- CSDN博客的一点小Bug(给CSDN的一点小小建议)
- Mac搭建Cocos2d-x v3.2 Android开发环境
- EasyARM i.mx287学习笔记——根文件系统rootfs修改和烧写
- 黑马视频学习笔记-OC-id、构造方法
- THE LAST OF US评论贴: 不完美的游戏,却无愧于满分的作品
- poj3274 hash数组
- Debugging of Chrome Android WebView
- matlab绘制立体图
- mysql存储过程
- Codeforces Round #261 (Div. 2)
- 原来阿里级别是这么定的。。。
- ASP.NET 缓存(Cache)
- ZOJ 2833-Friendship(并查集+优化)
- 折腾数组