The challenge of stealing Kidd time Limit:1000msmemory limit:32768kbthis problem'll be a judged onHDU. Original id:4552
64-bit integer IO format: %i64d Java class name: Main "On the most beautiful day of the tree, when the old man once again separates the clock, I will descend to the pyramid of the City of lights and take away the most precious smile." "This is the challenge of stealing Kidd to steal the Mona Lisa smile from the Louvre in Paris," he read.
But this time, a series of small letters "Aaab sdfeeddd ..." appeared on the challenge Book of The Strange Thief Kidd. Conan to the pupil's eyes, the brains of extraordinary high school students, fast statistics of various letter frequency, string length, and combined with the time of the challenge, and other information to try to analyze the intent of the strange Thief Kidd. Finally, he locks the thread to the number of loops in the string. Further reasoning is found, starting with the first bit of the string, to the I-bit, forming the substring of the string (c1, C2, C3 ... ci). For the number of occurrences of a substring CI in the string as Ki, the total number of cycles for all substrings is the sum of aim = k1 + K2 + ... + kn, Conan found that aim exactly corresponds to an ASCII code! So, as long as the challenge book on the string into a number, and then find the corresponding ASCII code, you can crack the challenge of the book!
Now, your task is to convert the string into corresponding numbers, because the ASCII code and the extended ASCII code all only 256, so the subject as long as the result of 256 to take the remainder.InputInput has multiple sets of test data;
Each set of test data has only one string, consisting of a variety of lowercase letters, with no spaces in the middle.
The length of the string is L (0 < L <= 100000).OutputPlease calculate and output the aim value of the string, one row for each set of data output.Sample Input
Aaaabab
Sample Output
66
Source2013 Gold Shanxi Mountain Lodge Creative Game Program Challenge--Preliminaries (3) solve the problem: ask for each suffix and the original string LCP
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =100010;4 CharS[MAXN];5 intSa[maxn],rk[maxn],height[maxn],n;6 intc[maxn],tmp[2][MAXN];7 voidBuild_sa (intm) {8 intI,*x = tmp[0],*y = tmp[1];9 for(i =0; I < m; ++i) C[i] =0;Ten for(i =0; I < n; ++i) C[x[i] = s[i]]++; One for(i =1; I < m; ++i) C[i] + = c[i-1]; A for(i = n1; I >=0; -i) sa[--c[x[i]] =i; - - for(intK =1; K <= N; K <<=1) { the intp =0; - for(i =0; I < m; ++i) C[i] =0; - for(i = n-k; i < n; ++i) y[p++] =i; - for(i =0; I < n; ++i)if(Sa[i] >= k) y[p++] = sa[i]-K; + for(i =0; I < n; ++i) c[x[y[i]]]++; - for(i =1; I < m; ++i) C[i] + = c[i-1]; + for(i = n-1; I >=0; -i) sa[--c[x[y[i] []] =Y[i]; A swap (x, y); atx[sa[0]] =0; - for(p = i =1; I < n; ++i) - if(Y[sa[i]] = = y[sa[i-1]] && y[sa[i]+k] = = y[sa[i-1]+K]) -X[sa[i]] = P1; - ElseX[sa[i]] = p++; - if((M = p) >= N) Break; in } - } to voidgetheight () { + intI,j,k =0; - for(i =0; I < n; ++i) Rk[sa[i] =i; the for(i =0; I < n; ++i) { * if(k)--K; $j = sa[rk[i]-1];Panax Notoginseng while(i + K < n && J + K < n && s[i+k] = = S[j+k]) + +K; -Height[rk[i]] =K; the } + } A intMain () { the while(~SCANF ("%s", s)) { +n = strlen (s) +1; -Build_sa ( -); $ getheight (); $ intpos = rk[0],TMP = n1, ret = n1; - while(POS +1< n &&tmp) { -tmp = MIN (tmp,height[++POS]); theRET + =tmp; - }Wuyipos = rk[0],TMP = n1; the while(Pos >1&&tmp) { -tmp = MIN (tmp,height[pos--]); WuRET + =tmp; - } Aboutprintf"%d\n", ret% the); $ } - return 0; -}View Code
HDU 4552 monster Thief Kidd's Challenge book