标签:des style blog http io ar for strong sp
| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions: 13511 | Accepted: 6368 |
Description
Input
Output
Sample Input
3 aaa 12 aabaabaabaab 0
Sample Output
Test case #1 2 2 3 3 Test case #2 2 2 6 2 9 3 12 4
Source
和poj1961相同,http://blog.csdn.net/winddreams/article/details/40268107
不过是多加了一个对从头到每个字符的判断。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int next[1100000] ;
char s[1100000] ;
void getnext(int l)
{
int j = 0 , k = -1 ;
next[0] = -1 ;
while( j < l )
{
if( k == -1 || s[j] == s[k] )
next[++j] = ++k ;
else
k = next[k] ;
}
}
int main()
{
int n , i , num = 1 , l ;
while(scanf("%d", &n) && n)
{
scanf("%s", s);
getnext(n);
printf("Test case #%d\n", num++);
for(i = 1 ; i <= n ; i++)
{
l = i - next[i] ;
if( i%l==0 && i/l != 1 )
printf("%d %d\n", i, i/l);
}
printf("\n");
}
return 0;
}
标签:des style blog http io ar for strong sp
原文地址:http://blog.csdn.net/winddreams/article/details/40268155