ACM模板库

ACM模板库


trie树(红黑树+节空间耗时间)

#include <iostream>
#include <string>
#include <cstring>
#include <map>
using namespace std;
struct Trie{
    int exist;
    map<int, Trie*> child;
    Trie():exist(0){}
};
int insert(Trie *t, const string &str){
    Trie *root = t;
    for(int i = 0; i < str.size(); i++){ 
        int place = str[i] - 'a';
        if(root->child.find(place) != root->child.end())  
            root = root->child[place]; 
        else{
            root->child[place] = new Trie();
            root = root->child[place];
        }
        if(i == str.size() - 1){
            root->exist++;
            return root->exist;
        }
    }
}

页面列表

ITEM_HTML