poj3274
来源:互联网 发布:ps如何制作淘宝详情页 编辑:程序博客网 时间:2024/05/01 16:27
#include <iostream>#include <set>#include <map>#include <queue>#include <math.h>#include <vector>#include <string>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using namespace std;const int size=100001;const int mod=99991;int feature[size][30];int sum[size][30];int c[size][30];int N,K,MaxLen;typedef class HASH{public: int pi; class HASH* next; HASH() { next=0; }}HashTable;HashTable* hash[mod];bool cmp(int a,int b){ int i; for(i=0;i<K;i++) if(c[a][i]!=c[b][i]) return false; return true;}void Hash(int ci){ int i,j,key=0; for(i=1;i<K;i++) key+=c[ci][i]*i; key=abs(key)%mod; if(!hash[key]) { HashTable* pn=new HashTable; pn->pi=ci; hash[key]=pn; return ; } HashTable* pn=new HashTable; pn=hash[key]; if(cmp(pn->pi,ci)) { int ans=ci-(pn->pi); MaxLen=MaxLen>ans? MaxLen:ans; return ; } while(pn->next) { if(cmp((pn->next->pi),ci)) { int ans=ci-(pn->next->pi); MaxLen=MaxLen>ans? MaxLen:ans; return ; } pn=pn->next; } HashTable* temp=new HashTable; temp->pi=ci; pn->next=temp; return ;}int main(){ int i,j; while(cin>>N>>K) { for(i=0;i<K;i++) sum[0][i]=c[0][i]=0; memset(hash,0,sizeof(hash)); MaxLen=0; Hash(0); for(i=1;i<=N;i++) { int temp,g; cin>>temp; for(j=0;j<K;j++) { feature[i][j]=temp%2; temp/=2; sum[i][j]=sum[i-1][j]+feature[i][j]; c[i][j]=sum[i][j]-sum[i][0]; } Hash(i); } cout<<MaxLen<<endl; } 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)
- [leetcode]Word Break
- [Leetcode] Binary Tree Upside Down
- strtok源码剖析 位操作与空间压缩
- 九度OJ-1172 哈夫曼树
- java的一些小程序的例子--1
- poj3274
- POJ 2528 线段树+离散化~
- tomcat不同版本所对应的JSP/Servlet版本
- [leetcode]Climbing Stairs
- Java基础第四天--多态
- FFmpeg源代码简单分析:libswscale的sws_scale()
- TCP建立连接和释放链接
- eclipse 搭建android5.0的开发环境
- asp.net的几个内置对象