poj3274
来源:互联网 发布:ubuntu有哪些好的软件 编辑:程序博客网 时间:2024/05/01 19:08
#include<stdio.h>#include <iostream>#include <string.h>using namespace std;const int MAX = 100010;const int Mod = 1001007;int Hash[Mod+100];int sum[MAX][40],cmp[MAX][40];int n,k;int has(int *s)//哈希值转化,题解看的,不明白{ int p=0; for(int i=0; i<k; i++) { p = ((p<<2)+(s[i]>>4))^(s[i]<<10); } p%=Mod; if(p<0) { p+=Mod; } return p;}int main(){ int data; int Max = 0; scanf("%d %d",&n,&k); memset(Hash,-1,sizeof(Hash)); Hash[has(cmp[0])]=0; for(int i=1; i<=n; i++) { scanf("%d",&data); for(int j=0; j<k; j++) { //sum[i][j]=data&1; sum[i][j]+=sum[i-1][j]+data%2; cmp[i][j]=sum[i][j]-sum[i][0]; data=data>>1; } int ans = has(cmp[i]); while(Hash[ans]!=-1) { int R; for(R=0; R<k; R++) { if(cmp[i][R]!=cmp[Hash[ans]][R]) { break; } } if(R==k) { if(Max<i-Hash[ans]) { Max=i-Hash[ans]; break; } } ans++; } if(Hash[ans]==-1) { Hash[ans]=i; } } printf("%d\n",Max); return 0;}
0 0
- POJ3274
- poj3274
- poj3274
- poj3274
- poj3274
- poj3274
- POJ3274
- poj3274
- poj3274 hash
- poj3274 hash
- Gold Balanced Lineup poj3274
- POJ3274 Gold Balanced Lineup
- poj3274 hash数组
- poj3274数位HASH
- poj3274 Gold Balanced Lineup
- [POJ3274]-Gold Balanced Lineup
- [POJ3274] Gold Balanced Lineup
- poj3274(数字hash)
- 论文写作中一些好的创意
- HDU/HDOJ 1260 Tickets(卖票问题,DP)
- 两种广播的区别
- redis学习以及扩展安装
- Ajax学习
- poj3274
- 学习iOS的第六天
- MemInfoReader
- MySQL在使用过程中的一些小问题
- 华为OJ——计算字符个数
- 致诸弟·劝弟谨记进德修业
- HUCM Contest 2016-02
- poj1699Best Sequence(TSP)
- 在web分发企业级app