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
  • 相关阅读:
    Java 内部类
    Java 包 和导入
    Java 访问控制权限
    java 面向对象-- this 关键字
    java 面向对象-- 构造方法
    java 用递归函数实现斐波那契数列 1、1、2、3、5、8、13、21
    Java面向对象-static静态方法与普通方法
    常用模块(time)
    模块安装及导入
    python之OS模块详解
  • 原文地址:https://www.cnblogs.com/onlyRP/p/5189566.html
Copyright © 2011-2022 走看看