Simple question about the UVA 12378 Ball blsting Game Manacher, 12378
Question link: Click the open link
Question:
In the string elimination game, if you select a letter, the same and continuous section of the letter will be eliminated, and the left and right sides will be merged. If the left and right sides of the letter are the same, the two sides will be eliminated again. The letters on both sides are different until they are merged.
The maximum number of consecutive elimination attempts.
Ideas:
First, treat the same consecutive letters as one letter, and then obtain the longest return 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 (char 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 ;}