trie树 HDU1671
来源:互联网 发布:suse查看开放端口号 编辑:程序博客网 时间:2024/06/16 12:59
#include <iostream>using namespace std;struct trie{trie():end(false){for(int i =0; i < 10; ++i)next[i] = NULL;}bool end;trie *next[10];};void insert(trie *root, const char *a){trie *p = root;int len = strlen(a);for(int i = 0; i < len; ++i){if(!p->next[a[i] - '0']){trie *t = new trie;p->next[a[i] - '0'] = t;}p = p->next[a[i] - '0'];}p->end = true;}bool search(trie *root, const char *a){trie *p = root;int len = strlen(a);for(int i = 0; i < len; ++i){int k = a[i] - '0';p = p->next[k];if(p->end){if(i + 1 != len)return true;}}return false;}void del(trie *p){if(!p)return;for(int i = 0; i < 10; ++i){if(p->next[i]){del(p->next[i]);}}delete p;}int main(void){//freopen("1.txt", "r", stdin);int t, n;bool fail;cin >> t;while(t--){trie *root = new trie;fail = false;char celnum[10010][11];cin >> n;for(int i = 0; i < n; ++i){scanf("%s", celnum[i]);insert(root, celnum[i]);}for(int j = 0; j < n; ++j){if(search(root, celnum[j]))fail = true;}if(fail)cout << "NO" << endl;elsecout << "YES" << endl;del(root);}return 0;}
0 0
- trie树 HDU1671
- hdu1671 trie树
- hdu1671 trie树
- Trie树(字典树)poj3630+hdu1671
- hdu1671(trie树(字典树))
- Trie树入门题目--HDU1671 Phone List
- hdu1671 Phone List (trie树)
- Phone List hdu1671 trie
- [复习][HDU1671]字典树(trie树)phone list
- ZOJ2876 POJ3630 HDU1671 Phone List,静态Trie树
- Trie树学习小记 Poj 3630 & Hdu1671 Phone List
- C++——字典树(Trie树)例题——Phone List(POJ3630)(HDU1671)
- Trie的C++实现及HDU1251,hdu1671
- HDU1671字典树
- hdu1671之字典树
- hdu1671( 字典树)
- hdu1671 字典树 入门
- 字典树HDU1671
- jquery(四)JQuery框架操作元素的属性与样式
- 互斥对象使用CreateMutex
- 数据库查询效率
- android 应用启动出现actionbar 或者空白界面
- 内部类之链接到外部类
- trie树 HDU1671
- 悟道—位IT高管20年的职场心经(读书笔记六)
- POJ-3646-Loowater的龙
- 使用3.0实现微信打飞机——10.用户数据的操作
- C/C++排序算法总结
- php数组随机抽取函数shuffle()和array_rand()
- jquery(五)jquery中的ajax详解
- oracle 表约束的添加、修改以及约束的禁用启用
- Android学习之路