Chuyển đến nội dung chính

Bài đăng

Đang hiển thị bài đăng từ Tháng 1, 2021

Học vẽ hình bằng AI

 

Bí Kíp Ôn Luyện Pro

#HASH Chuyen 1 array sang kieu long long #define a 96 long long hash(char c[]) { int i=0; long long h =0; while(c[i]!='\0') { h=(h<<5)+c[i]-a; i++; } return h; } #TRIE typedef struct TrieNode{ int id; TrieNode *child[26]; } TrieNode; TrieNode *createNewNode() { TrieNode *p=new TrieNode(); p->id=-1; for(int i=0;i<26;i++) { p->child[i]=NULL; } return p; } void insert(char c[]) { TrieNode *p=root; for(int i=0;c[i];i++) { int index =c[i]-'a'; if(p->child[index]==NULL) { p->child[index]=createNewNode(); } p=p->child[index]; } p->id=index++; } void remove(char c[]) { TrieNode *p=root; for(int i=0;c[i];i++) { int index =c[i]-'a'; if(p->child[index]==NULL) { return; } p=p->child[index]; } p->id=-1; } bool search(char c[]) { TrieNode *p=root; for(int i=0;c[i];i++) { if(p>child[index]==NULL) { return false; } ...