zoukankan      html  css  js  c++  java
  • luogu_P3121 [USACO15FEB]审查(黄金)Censoring (Gold)

    栈模拟,哈希

    #include<iostream> 
    #include<cstdio>
    
    #define ri register int
    #define u unsigned long long
    
    namespace opt {
        
        inline u in() {
            u x(0),f(1);
            char s(getchar());
            while(s<'0'||s>'9') {
                if(s=='-') f=-1;
                s=getchar();
            }
            while(s>='0'&&s<='9') {
                x=(x<<1)+(x<<3)+s-'0';
                s=getchar();
            }
            return x*f;
        }
        
    }
    
    using opt::in;
    
    #define NN 500005
    
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    
    namespace mainstay {
        
        const u bas=131;
        
        char s[NN],t[NN];
        
        u N,sum[NN],pr,ans[NN];
        
        struct node{
            u len,val;
        }a[NN];
        
        inline bool cmp(const node &x,const node &y){
            return x.len<y.len;
        }
            
        u pow[NN];
            
        inline void solve(){
            scanf("%s",s+1);
            scanf("%d",&N);
            for(ri i(1);i<=N;++i) {
                scanf("%s",t+1);
                a[i].len=(std::strlen(t+1));
                for(ri j(1);j<=a[i].len;++j){
                    a[i].val=a[i].val*bas+(t[j]-'a'+1);
                }
            }
            pow[0]=1;
            u len(std::strlen(s+1));
            for(ri i(1);i<=len;++i) pow[i]=pow[i-1]*bas;
            std::sort(a+1,a+N+1,cmp);
            u i(0);
            for(ri i(0);i<=len;){
                ans[++pr]=s[++i]-'a'+1,sum[pr]=sum[pr-1]*bas+s[i]-'a'+1;
                while(pr<a[1].len) ans[++pr]=s[++i]-'a'+1,sum[pr]=sum[pr-1]*bas+s[i]-'a'+1;
                for(ri j(1);j<=N;++j){
                    if(a[j].len<=pr){
                        u _w(sum[pr]-sum[pr-a[j].len]*pow[a[j].len]);
                        if(_w==a[j].val){
                            pr-=a[j].len;
                            break;
                        }
                    }
                    else break;
                }
            }
            for(ri i(1);i<=pr;++i) printf("%c",ans[i]+'a'-1);
        }
        
    }
    
    int main() {
        
        //freopen("x.txt","r",stdin);
        std::ios::sync_with_stdio(false);
        mainstay::solve();
        
    }
  • 相关阅读:
    SqlHelper
    C#中gridView常用属性和技巧介绍
    oracle中的存储过程例子
    log4j.properties配置详解
    Ant之build.xml
    jQuery源码
    jQuery实现分页
    mysql中log
    SQL只获取字段中的中文字符
    子Repeater获取父级Repeater绑定项的值
  • 原文地址:https://www.cnblogs.com/ling-zhi/p/11827863.html
Copyright © 2011-2022 走看看