HDU 3336 Count the string(乱搞)

题目链接

有点BFS的思想,不过还是感觉像是乱搞题。。

 1 #include <stdio.h>

 2 #include <string.h>

 3 #include <stdlib.h>

 4 #define N 200001

 5 #define M 10007

 6 char str[N];

 7 int p[N];

 8 int main()

 9 {

10     int i,j,t,n,start,end,ans;

11     scanf("%d",&t);

12     while(t--)

13     {

14         scanf("%d%*c",&n);

15         gets(str);

16         ans = n%M;

17         start = 0;

18         j = 0;

19         for(i = 1;i <= n-1;i ++)

20         {

21             if(str[i] == str[0])

22             {

23                 p[j] = i;

24                 ans++;

25                 j ++;

26             }

27         }

28         end = j-1;

29         for(i = 1;i <= n-1;i ++)

30         {

31             j = 0;

32             while(start <= end)

33             {

34                 if(str[p[start]+1] == str[i])

35                 {

36                     ans++;

37                     p[j] = p[start]+1;

38                     j ++;

39                 }

40                 start ++;

41             }

42             if(ans > M)

43             ans = ans%M;

44             if(j == 0)

45             break;

46             start = 0;

47             end = j-1;

48         }

49         printf("%d\n",ans);

50     }

51     return 0;

52 }

你可能感兴趣的:(String)