# UVA 12378 ball blasting Game manacher nude questions

Source: Internet
Author: User

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

[CPP]View Plaincopy
2. #include <cstdio>
3. #include <cstring>
4. #include <iostream>
5. Using namespace std;
6. const int maxn = 110010;
7. String length <MAXN
8. Char MA[MAXN * 2];
9. int MP[MAXN * 2];
10. int Manacher (char s[]) {
11. int l = 0, Len = strlen (s);
12. ma[l++] = ' \$ ';
13. ma[l++] = ' # ';
14. For (int i = 0; i<len; i++) {
15. ma[l++] = s[i];
16. ma[l++] = ' # ';
17. }
18. Ma[l] = 0;
19. int mx = 0, id = 0;
20. For (int i = 0; i<l; i++) {
21. Mp[i] = mx>i? Min (mp[2 * id-i], mx-i): 1;
22. while (Ma[i + mp[i]] = = Ma[i-mp[i]]) mp[i]++;
23. if (i + mp[i]>mx) {
24. MX = i + mp[i]; id = i;
25. }
26. }
27. int ans = 0;
28. For (int i = 0; I<2 * len + 2; i++)
29. ans = max (ans, mp[i]-1);
30. return ans;
31. }
32. Char d[100100], s[100100];
33. int main () {
34. int T; cin>>t;
35. While (t--) {
36. scanf ("%s", d);
37. int top = 0;
38. S[0] = d[0];
39. For (int i = 1; d[i]; i++)
40. if (D[i]!=s[top])
41. S[++top] = D[i];
42. S[++top] = 0;
43. printf ("%d\n", (Manacher (s) +1)/2);
44. }
45. return 0;
46. }

UVA 12378 ball blasting Game manacher nude questions

Related Keywords:

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.