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 |
Re:简化In Reply To:简化 Posted by:godofwa2 at 2013-07-20 00:52:46 嗯我就是这样做的 for(int i = c; i; i = fail[i]) _res[c-fail[i]] = 1; 这样就把一行的所有循环节弄出来了。 不过我觉得应该还可以利用循环节的性质优化,而不用记录每行的所有循环节。 附个代码 char s[10000][76]; short fail[10001] = {-1}; inline char row(int r, int c) { return s[r][c]; } inline char col(int r, int c) { return s[c][r]; } inline int bazinga(int r, int c, char s(int, int)) { bitset<10001> res; for(int _r = 0; _r<r; _r++) { for(int i = 0, j = -1; i<c; ) if(j==-1 || s(_r, i)==s(_r, j)) fail[++i] = ++j; else j = fail[j]; //for(int i = 1; i<=c; i++) // cout<<fail[i]<<'\t'; //cout<<endl; bitset<10001> _res; for(int i = c; i; i = fail[i]) _res[c-fail[i]] = 1; if(_r) res &= _res; else res = _res; if(res.count()==1) return c; } for(int i = 1; i<=c; i++) if(res[i]) return i; return -1; } int main() { #ifndef ONLINE_JUDGE freopen("/Users/dan/git/Main/input.txt", "r", stdin); #endif int r, c; scanf("%d%d", &r, &c); for(int i = 0; i<r; i++) scanf("%s", s[i]); printf("%d\n", bazinga(r, c, row)*bazinga(c, r, col)); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator