HDU - 1358 Period
Posted duck_lu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 1358 Period相关的知识,希望对你有一定的参考价值。
1 #include <iostream> 2 #include <algorithm> 3 #define MaxSize 1000010 4 using namespace std; 5 6 char s[MaxSize]; 7 int Next[MaxSize]; 8 int Len; 9 10 void GetNext() 11 { 12 int i = 0, j = Next[0] = -1; 13 while (i < Len) 14 { 15 if (j == -1 || s[i] == s[j]) 16 Next[++i] = ++j; 17 else 18 j = Next[j]; 19 } 20 } 21 22 int main() 23 { 24 ios::sync_with_stdio(false); 25 int cas = 0; 26 while (true) 27 { 28 cin >> Len; 29 if (Len == 0) 30 break; 31 cin >> s; 32 cas++; 33 GetNext(); 34 cout << "Test case #" << cas << endl; 35 for (int i = 1; i <= Len; ++i) 36 { 37 int circle = i - Next[i]; 38 if (Next[i] == 0) 39 continue; 40 if (i % circle == 0) 41 cout << i << ‘ ‘ << i / circle << endl; 42 } 43 cout << endl; 44 } 45 46 return 0; 47 }
以上是关于HDU - 1358 Period的主要内容,如果未能解决你的问题,请参考以下文章