标签:line math ice cat forever comm 包括 scan return
http://acm.hdu.edu.cn/showproblem.php?pid=3336
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17068 Accepted Submission(s): 7721
#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> using namespace std; char a[200009]; int num; 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++; // if(a[j] != a[k]) next[j] = k ; // else // { // next[j] = next[k]; // } } else { k = next[k]; } } } int main() {int n ; scanf("%d" , &n); while(n--) { int next[200009]; int l ; scanf("%d" , &l); scanf("%s" , a); getnext(a , l , next); int j = 0 ; for(int i = 0 ; i <= l ; i++) { // cout << next[i] << " " ; j = i ; while(next[j] > 0) { num = (num + 1) % 10007 ; j = next[j]; } } // cout << endl ; printf("%d\n" , (num + l)%10007); num = 0 ; } return 0 ; }
标签:line math ice cat forever comm 包括 scan return
原文地址:https://www.cnblogs.com/nonames/p/11296242.html