zoukankan      html  css  js  c++  java
  • bzoj 1212

    tire入门,死得好惨。。。

     1 #include<bits/stdc++.h>
     2 #define inc(i,l,r) for(int i=l;i<=r;i++)
     3 #define dec(i,l,r) for(int i=l;i>=r;i--)
     4 #define link(x) for(edge *j=h[x];j;j=j->next)
     5 #define mem(a) memset(a,0,sizeof(a))
     6 #define inf 1e9
     7 #define ll long long
     8 #define succ(x) (1<<x)
     9 #define lowbit(x) (x&(-x))
    10 #define NM 2100000+5
    11 using namespace std;
    12 int read(){
    13     int x=0,f=1;char ch=getchar();
    14     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    15     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    16     return x*f;
    17 }
    18 struct node{
    19     bool f;
    20     node *c[27];
    21 }*root,N[500],*o=N;
    22 char st[NM];
    23 int n,m,p;
    24 bool f[NM];
    25 int main(){
    26     freopen("data.in","r",stdin);
    27     m=read();p=read();
    28     root=++o;
    29     while(m--){
    30         scanf("%s",st+1);
    31         n=strlen(st+1);
    32         node *t=root;
    33         inc(i,1,n){
    34             if(!t->c[st[i]-'a'])t->c[st[i]-'a']=++o;
    35             t=t->c[st[i]-'a'];
    36         }
    37         t->f=1;
    38     }
    39     while(p--){
    40         mem(f);
    41         scanf("%s",st+1);
    42         n=strlen(st+1);f[0]++;
    43         node *t;int j;
    44         inc(i,0,n)if(f[i])
    45         for(t=root,j=i+1;t->c[st[j]-'a']&&j<=n;j++){
    46             t=t->c[st[j]-'a'];
    47             if(t->f)f[j]=true;
    48         }
    49         dec(i,n,0)if(f[i]){
    50             printf("%d
    ",i);
    51             break;
    52         }
    53     }
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    Click: 命令行工具神器
    Pipenv: Python包管理神器
    如何让你的Python程序支持多语言
    Volatile变量
    简单排查java应用CPU飙高的线程问题
    java中的clone
    接口限流
    HTTP协议详解
    [转]nginx 源码学习笔记(十五)—— ngx_master_process_cycle 多进程(一)
    nginx slab内存管理
  • 原文地址:https://www.cnblogs.com/onlyRP/p/5189566.html
Copyright © 2011-2022 走看看