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)