Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
转化 + 开散列#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> using namespace std; const int N = 100000 + 7; const int M = 30 + 1; int n, m; int sum[N][M], delta[N][M], ht[N], table[M]; inline int hash(int idx) { int key = 0; for (int i = 1; i <= m; i++) key = key * 10 + delta[idx][i]; return abs(key) % N; } inline bool check(int idx1, int idx2) { for (int i = 1; i <= m; i++) if (delta[idx1][i] != delta[idx2][i]) return false; return true; } inline int insert(int idx) { int key = hash(idx); while (ht[key] != -1) { if ( check(idx, ht[key]) ) return idx - ht[key]; key = (key + 1) % N; } ht[key] = idx; return 0; } int main() { int maxLen = 0, tmpLen; for (int i = 1; i <= N; i++) ht[i] = -1; scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) table[i] = 1 << (i - 1); for (int i = 1; i <= n; i++) { int tmp; scanf("%d", &tmp); for (int j = 1; j <= m; j++) sum[i][j] = sum[i - 1][j] + (tmp & 1), tmp >>= 1, delta[i][j] = sum[i][j] - sum[i][1]; } for (int i = 1; i <= n; i++) if ( (tmpLen = insert(i)) > maxLen ) maxLen = tmpLen; printf("%d\n", maxLen); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator