• HDU 3695 简单题


    题意   还是前面题目的意思;  只是需要解码

    方法   不说了

    #include<iostream>
    #include<stdio.h>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    
    char str[5123456],sss[5123456],cha[1123];
    
    struct date
    {
        date *next[27],*fail;
        bool fell;
        int sum;
    }tree[451234],*que[451234],*root;
    int tail,head,ptr;
    
    date *creat_node( )
    {
        for( int i = 0; i < 26; i++ )
        tree[ptr].next[i] = NULL;
        tree[ptr].fail = NULL;
        tree[ptr].fell = false;
        tree[ptr].sum = 0;
        return &tree[ptr++];
    }
    
    void inint( )
    {
        tail = head = ptr = 0;
        root = creat_node( );
    }
    
    void insert( char *word )
    {
        date *temp = root;
        while( *word )
        {
            int num = *word - 'A';
            if( temp->next[num] == NULL )
                temp->next[num] = creat_node();
            temp = temp->next[num];
            word++;
        }
        temp->sum++;
    }
    
    void build_AC( )
    {
        que[tail++] = root;
        while( tail > head )
        {
            date *temp = que[head++];
            for( int i = 0; i < 26; i++ )
            if( temp->next[i] != NULL )
            {
                if( temp == root ) temp->next[i]->fail = root;
                else               temp->next[i]->fail = temp->fail->next[i];
                temp->next[i]->fell = true;
                que[tail++] = temp->next[i];
            }
            else
            {
                if( temp == root ) temp->next[i] = root;
                else               temp->next[i] = temp->fail->next[i];
            }
        }
    }
    
    int query( char *word )
    {
        date *partten,*temp = root;
        int ans = 0;
        while( *word )
        {
            int num = *word - 'A';
            temp = temp->next[num];
            partten = temp;
            while( partten != root )
            {
                if( partten->fell )
                {
                    partten->fell = false;
                    ans += partten->sum;
                }
                else break;
                partten = partten->fail;
            }
            word++;
        }
        return ans;
    }
    
    int main( )
    {
        int T,N,i;
        scanf("%d",&T);
        while( T-- )
        {
            scanf("%d",&N);
            inint();
            for( i = 1; i <= N; i++ )
            {
                scanf("%s",&cha);
                insert( cha );
            }
                build_AC( );
            scanf("%s",&str);
            int len = strlen( str ),num,k = 0;
            bool fell = false;
            for( i = 0; i < len; i++ )
            {
                if( fell )
                {
                    if( str[i] - '0' >= 0 && str[i] - '0' <= 9 )
                         num = num*10 + ( str[i] - '0' );
                    else
                    {
                        while( num-- )sss[k++] = str[i];
                        fell = false;
                    }
                    continue;
                }
                if( str[i] == '[' )
                {
                    num = 0,fell = true;
                    continue;
                }
                if( str[i] - 'A' >= 0 && str[i] - 'A' <= 25 ) sss[k++] = str[i];
            }
            sss[k] = '\0';
            int a = query( sss );
            reverse( sss, sss + k );
            a += query( sss );
            printf("%d\n",a);
        }
    }
    

      

  • 相关阅读:
    GIT → 04:Git与代码托管平台
    GIT → 03:Git的下载和安装
    GIT → 02:Git和Svn比较
    GIT → 01:学习版本控制的原因
    GIT → 00:GIT学习大纲
    GIT → 10:基于IntelliJ IDEA的Git 操作
    GIT → 11:Git 工作流与实战演练
    GIT → 09:TortoiseGit 图形化工具
    亚马逊服务器搭建pptp方法
    Safari获取UDID需要安装.mobileconfig文件,
  • 原文地址:https://www.cnblogs.com/wulangzhou/p/3016528.html
Copyright © 2020-2023  润新知