zoukankan      html  css  js  c++  java
  • 回文树1960. Palindromes and Super Abilities

    Bryce1010模板

    http://acm.timus.ru/problem.aspx?space=1&num=1960
    这里写图片描述

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn = 100010;
    struct PalindromicTree{
        int fail[maxn],len[maxn],son[maxn][26];
        int tot,last,n;
        char s[maxn];
        int newnode(int slen = 0){
            memset(son[tot],0,sizeof son[tot]);
            len[tot] = slen;
            return tot++;
        }
        void init(){
            n = tot = last = 0;
            newnode(0);
            newnode(-1);
            fail[1] = fail[0] = 1;
            s[n] = -1;
        }
        int getFail(int x){
            while(s[n - len[x] - 1] != s[n]) x = fail[x];
            return x;
        }
        void extend(int c){
            s[++n] = c;
            int cur = getFail(last);
            if(!son[cur][c]){
                int x = newnode(len[cur] + 2);
                fail[x] = son[getFail(fail[cur])][c];
                son[cur][c] = x;
            }
            last = son[cur][c];
        }
    }pt;
    char str[maxn];
    int main(){
        while(~scanf("%s",str)){
            pt.init();
            bool flag = false;
            for(int i = 0; str[i]; ++i){
                pt.extend(str[i] - 'a');
                if(flag) putchar(' ');
                printf("%d",pt.tot - 2);
                flag = true;
            }
            putchar('
    ');
        }
        return 0;
    }
  • 相关阅读:
    13-17读后感
    读10 11 12章
    读书作业
    5.2.3
    测试与封装
    作业四
    作业三
    实验四 主存空间的分配和回收模拟
    评论
    实验三 进程调度模拟程序
  • 原文地址:https://www.cnblogs.com/bryce1010/p/9386881.html
Copyright © 2011-2022 走看看