标签:names ams begin -- main asi sub scanf name
http://acm.hdu.edu.cn/showproblem.php?pid=4763
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5815 Accepted Submission(s): 2890
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <algorithm> #include <iostream> #include<cstdio> #include<string> #include<cstring> #include <stdio.h> #include <string.h> #define INF 10000000 using namespace std; char a[1000009] , b[1000009], str[200009]; int ans = 0 ; void getnext(char *a , int len , int *next) { next[0] = -1 ; int k = -1 , j = 0 ; while(j < len) { if(k == -1 || a[j] == a[k]) { k++; j++; next[j] = k ; } else { k = next[k]; } } } int main() { int n ; scanf("%d" , &n); while(n--) { int next[1000009]; int next1[1000009]; scanf("%s" , a); int len = strlen(a); getnext(a , len , next); int q = next[len]; while(q > 0) { if(q * 3 > len) { q = next[q]; continue ; } for(int i = 0 ; i < q ; i++) { str[i] = a[i] ; } getnext(a , q , next1); int j = 0 , i = q ; while(i < len - q && j < q) { if(j == -1 || str[j] == a[i]) { i++; j++; } else { j = next[j] ; } } if(j == q) { ans = q; break ; } q = next[q]; } printf("%d\n" , q); } return 0 ; }
标签:names ams begin -- main asi sub scanf name
原文地址:https://www.cnblogs.com/nonames/p/11296313.html