URAL 2040 (palindrome automatic machine)

Source: Internet
Author: User

Problem Palindromes and Super abilities 2

Main topic

Analysis of Problem solving

Reference Program

1#include <map>2#include <Set>3#include <stack>4#include <queue>5#include <cmath>6#include <ctime>7#include <string>8#include <vector>9#include <cstdio>Ten#include <cstdlib> One#include <cstring> A#include <iostream> -#include <algorithm> - #pragmaComment (linker, "/stack:102400000,102400000") the using namespacestd; -  - #defineN 5000008 - #defineV 1008 + #defineE 60008 - #defineLson l,m,rt<<1 + #defineRson m,r+1,rt<<1|1 A #defineCLR (x,v) memset (x,v,sizeof (x)); at #defineLL Long Long -  - Const intMo =1000000007; - Const intINF =0x3f3f3f3f; - Const intINF =2000000000; - /**************************************************************************/  in intN,cnt,last; - intnt[n][2],size[n],len[n],fail[n]; to CharS[n]; +  - voidinit () { thefail[0]=fail[1]=1; *len[1]=-1; $last=0; Cnt=1;Panax Notoginseng } - voidInsertintCintN) { the     intp=Last ; +      while(s[n-len[p]-1]!=s[n]) p=Fail[p]; A     if(!Nt[p][c]) { the         intnow=++cnt,k=Fail[p]; +len[now]=len[p]+2;  -          while(s[n-len[k]-1]!=s[n]) k=Fail[k]; $FAIL[NOW]=NT[K][C]; nt[p][c]=Now ; $Putchar ('1'); -     } -     ElsePutchar ("0"); thelast=Nt[p][c]; -size[last]++;Wuyi } the  - voidsolve () { Wu      for(inti=cnt;i>=1; i--) size[fail[i]]+=Size[i]; - } About intMain () { $Gets (s+1); - init (); -N=strlen (s+1); -      for(intI=1; i<=n;i++) Insert (s[i]- the, i); A}
View Code

URAL 2040 (palindrome automatic machine)

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.