Hdoj 3068 longest retrieval [manacher algorithm ],

Source: Internet
Author: User

Hdoj 3068 longest retrieval [manacher algorithm ],

Meaning...

In the traditional method, timeout is required (that is, parity is required ).

Manacher algorithms: Baidu has explained a lot.


Commemorative code:

# Include <stdio. h> # include <string. h >#include <algorithm> using namespace std; # define M 110010 char a [M], B [M <1]; int p [M <1]; int main () {while (~ Scanf ("% s", & a [1]) {// int len = strlen (a); int I, len; for (I = 1; a [I]! = '\ 0'; I ++) {B [I <1] = a [I]; B [(I <1) + 1] = '#';} len = (I <1) + 2; B [0] = '@'; B [1] = '#'; B [len] = 0; // printf ("% d % s. ", len, & B [1]); int maxid, id, max; maxid = max = id = 0; for (I = 1; I <len; I ++) {if (maxid> I) {p [I] = min (p [2 * id-I], maxid-I);} else p [I] = 1; while (B [I-p [I] = B [I + p [I]) ++ p [I]; if (maxid <p [I] + I) {// each maxid <p [I + I] updates the maxid and id. Maxid = p [I] + I; id = I;} if (max <p [I]) max = p [I]; // printf ("% d .. ", p [I]);} printf (" % d \ n ", max-1);} return 0 ;}

Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 3068




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.