UVA 12378 ball blasting Game manacher nude questions

Source: Internet
Author: User

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

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.