Title: Give a series of only AB, find the half palindrome of the K large.
Idea: Violence to cite all half palindrome string, and then violence into the trie query K large, originally written trie is copy template, this time I wrote a bit.
#include <iostream>#include<map>#include<algorithm>#include<cstdio>#include<cstring>#include<cstdlib>#include<vector>#include<queue>#include<stack>#include<functional>#include<Set>#include<cmath>#definePB Push_back#defineFS First#defineSe Second#defineSq (x) (x) * (x)#defineEPS 0.0000000001#defineIinf (1<<30)using namespaceStd;typedefLong LongLl;typedef pair<ll,ll>P;Const intCharsize=2;Const intmaxv=5005;Const intMaxpool=25000000;BOOLISPA[MAXV][MAXV];CharSTR[MAXV];intlen,k;structnode{intnum; intsum; Node*Ch[charsize]; Node (): Num (0), SUM (0){};} Pool[maxpool]; Node*NULL=NewNode ();intPoolh=0; Node*NewNode () {Node*n=&pool[poolh++]; for(intI=0; i<charsize;i++) n->ch[i]=NULL; N->sum=n->num=0; returnN;} Node*root=NewNode ();voidInsert (node* N,intPints) { while(p<Len) { if(n->ch[str[p]-'a']==NULL) n->ch[str[p]-'a']=NewNode (); if(Ispa[s][p]) n->ch[str[p]-'a']->num++; N=n->ch[str[p]-'a'],p++; }}voidCul (Node *N) { if(n==NULL)return; N->sum=n->num; for(intI=0; i<charsize;i++) {Cul (n-Ch[i]); N->sum+=n->ch[i]->sum; }}voidOutput (Node *n,intk) { if(n==NULL|| k<=0)return; intsum=0; for(intI=0; i<charsize;i++){ if(sum+n->ch[i]->sum>=k) {printf ("%c",(Char)('a'+i)); Output (n->ch[i],k-sum-n->ch[i]->num); return; } Sum+=n->ch[i]->sum; } return;}voidgetpa () { for(intI=0; i<len;i++){ for(intj=0; j<=len;j+=2){ if(i-j<0|| i+j>=Len) { Break; } if(str[i+j]==str[i-J]) {Ispa[i-j][i+j]=1; }Else{ Break; } } for(intj=1; j<=len;j+=2){ if(i-j<0|| i+j>=Len) { Break; } if(str[i+j]==str[i-J]) {Ispa[i-j][i+j]=1; }Else{ Break; } } for(intj=0; j<=len;j+=2){ if(i-j<0|| i+j+1>=len) { Break;} if(str[i-j]==str[i+j+1]) {ispa[i-j][i+j+1]=1; }Else{ Break; } } for(intj=1; j<=len;j+=2){ if(i-j<0|| i+j+1>=len) { Break;} if(str[i-j]==str[i+j+1]) {ispa[i-j][i+j+1]=1; }Else{ Break; } } }}intMain () {Freopen ("/home/files/cppfiles/in","R", stdin); /*Std::ios::sync_with_stdio (FALSE); Std::cin.tie (0);*/scanf ("%s", str); Len=strlen (str); CIN>>K; GETPA (); for(intI=0; i<len;i++) Insert (root,i,i); Cul (root); Output (root,k); return 0;}
View Code
codeforces-557e (trie