P3879 [TJOI2010]阅读理解

很水的tire树,记得去掉重复的单词

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
template<class T>
void read(T &now){
    now=0;
    char c=getchar();
    int f=1;
    while((!isdigit(c))){
        if(c=='-') f=-1;
    //  cout<<isdigit(c)<<" "<<c<<" ";
        c=getchar();
    }
    while(isdigit(c)){
        now=(now<<1)+(now<<3)+c-'0';
        c=getchar();
    }
    now*=f;
}
int n;
int m;
string s;
int tr[510005][30];
vector<int> v[3000005];
int cnt;
void add(string s,int id){
    int p=0;
    int l=s.length();
    for(int i=0;i<l;++i){
        int x=s[i]-'a';
        if(!tr[p][x]) tr[p][x]=++cnt;
        p=tr[p][x];
    }
    if(!v[p].empty()&&v[p][v[p].size()-1]==id) return ;
    v[p].push_back(id);
    //cout<<s<<" "<<p<<endl;
}
void que(string s){
    int p=0;
    int l=s.length();
    for(int i=0;i<l;++i){
        int x=s[i]-'a';
        if(!tr[p][x]) {
            puts("");
            return ;
        }
        p=tr[p][x];
    }
    for(auto x:v[p]){
        printf("%d ",x);
    }
    puts("");
}
int main(){
    read(n);
    for(int i=1;i<=n;++i){
        read(m);
        for(int j=1;j<=m;++j){
            cin>>s;
            add(s,i);
        }
    }
    read(m);
    for(int i=1;i<=m;++i){
        cin>>s;
        que(s);
    }
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇