Simple question about the UVA 12378 Ball blsting Game Manacher, 12378

Source: Internet
Author: User

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 ;}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.