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\n",i);
51             break;
52         }
53     }
54     return 0;
55 }
View Code

 

posted on 2016-02-14 20:48  onlyRP  阅读(232)  评论(0编辑  收藏  举报