Topic Link: Click to open the link
Test instructions
To eliminate the string game, select a letter, you will eliminate the same letter and a continuous paragraph, and then close the left and right sides, if the letters on both sides of the same letter will be eliminated again. The letters are not the same on both sides until the closure.
Ask for the maximum number of consecutive elimination.
Ideas:
First, the same letter as a letter, and then the longest palindrome string,
The answer is (maximum length + 1)/;2
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <cstring> #include < iostream>using namespace Std;const int maxn = 110010;//string length <maxnchar MA[MAXN * 2];int MP[MAXN * 2];int Manacher (cha R S[]) {int L = 0, Len = strlen (s); ma[l++] = ' $ '; ma[l++] = ' # '; for (int i = 0; i<len; i++) {ma[l++] = s[i]; ma[l++] = ' # ';} MA[L] = 0;int mx = 0, id = 0;for (int i = 0; i<l; i++) {Mp[i] = mx>i? min (mp[2 * id-i], mx-i): 1;while (ma[i + Mp[i]] [= Ma[i-mp[i]]) mp[i]++;if (i + mp[i]>mx) {mx = i + mp[i]; id = i;}} int ans = 0;for (int i = 0; I<2 * len + 2; i++) ans = max (ans, mp[i]-1); return ans; Char d[100100], S[100100];int main () {int T; cin>>t; while (t--) {scanf ("%s", d); int top = 0; S[0] = d[0]; for (int i = 1; d[i]; i++) if (D[i]!=s[top]) s[++top] = D[i]; S[++top] = 0;printf ("%d\n", (Manacher (s) +1)/2);} return 0;}
UVA 12378 ball blasting Game manacher nude questions