Пример #1
0
    void make_dat(std::vector<KeyValue>& lexicon,int no_prefix=0){
        std::sort(lexicon.begin(),lexicon.end(),&compare_words);

        int size=(int)lexicon.size();
        //std::cout<<size<<"\n";
        std::vector<int> children;
        Word prefix;
        //prefix.clear();
        gen_children(lexicon,0,prefix,children);
        //std::cout<<"children size: "<<children.size()<<"\n";
        int base=assign(0,children,true);
        dat[0].base=base;
        for(int i=0;i<(int)lexicon.size();i++){
            //std::cout<<"i "<<i<<"\n";
            Word& word=lexicon[i].first;//得到第一个词
            int off=this->get_info(word);
            //std::cout<<"off: "<<off<<" length of word: "<<word.size()<<"\n";
            //for(int j=0;j<word.size();j++){
            //    std::cout<<(int)word[j]<<" ";
            //};std::cout<<"\n";
            if(off<=0)off=(int)word.size();
            for(int offset=off;offset<=(int)word.size();offset++){
                //prefix=Word(word.pt,offset);
                prefix=Word(word,offset);

                int p_base=-this->get_info(prefix);
                //std::cout<<"p_base "<<p_base<<"\n";
                    
                gen_children(lexicon,i,prefix,children);
                int base=assign(p_base,children,offset==(int)word.size());
            }
            off=-this->get_info(word);
            if(no_prefix){
                dat[off].base=lexicon[i].second;
            }else{
                dat[dat[off].base].base=lexicon[i].second;
            }
            //if(i&&(i%100000==0))printf("%f\n",(double)i/size);
            //int zkx;
            //std::cin>>zkx;
        }

    }
Пример #2
0
int main()
{
    int start, dest, nr_cases, nr_exclude, i, nump;

    scanf("%d\n\n", &nr_cases);
    dprintf("num cases: %d\n", nr_cases);
    for (i = 0; i < nr_cases; i++) {
        init();
        start = get_num();
        dest = get_num();
        scanf("%d\n", &nr_exclude);
        dprintf("start: %d, dest: %d, num to exclude: %d\n", start, dest, nr_exclude);
        scan_excludes(nr_exclude);
        nump = gen_children(start, dest);
        if (nump) {
            dprintf("found path %d\n", nump);
            printf("%d\n", nump);
        } else {
            dprintf("path does not exist\n");
            printf("%d\n", -1);
        }
    }
    return 0;
}