zoj 2876 Phone List【字典树】【水】
来源:互联网 发布:js实现二级联动菜单 编辑:程序博客网 时间:2024/05/16 17:25
如果一个号码就是另外一个号码的前缀就输出NO
注意应该将号码按照长度升序排序。
写的很乱,本来这个代码就不是为了这道题写的。
我只是测试一下这种建树的方式对不对
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <algorithm>#define _MAX 1000000#define MAXSON 10#define BASE -'0'using namespace std;typedef struct __node{int next, key;}node;node m[_MAX];int nlen;void newNode(int n){m[n].next = -1;m[n].key = -1;}void init(){}void buildNode(int n){int i;m[n].next = nlen;for(i=0; i<MAXSON; i++){newNode(nlen);nlen ++;}}int addNode(char *s){int i, p=0;for(i=0; i<strlen(s); i++){if(m[p].next == -1)buildNode(p);p = m[p].next + s[i] + BASE;if(m[p].key != -1)return 0;}m[p].key = 1;return 1;}int cmp(const void *a, const void *b){return strlen((char *)a ) - strlen((char *)b);}int main(){int i, n, flag, t;char s[10001][100];scanf("%d", &t);while(t--){flag = 1;nlen = 1;newNode(0);scanf("%d", &n);for(i=0; i<n; i++)scanf(" %s", s[i]);qsort(s, n, sizeof(s[0]), cmp);for(i=0; i<n; i++)if(flag)flag = addNode(s[i]);if(flag == 0)printf("NO\n");elseprintf("YES\n");}return 0;}
- zoj 2876 Phone List【字典树】【水】
- ZOJ-1875-Phone List-字典树
- zoj 2876 Phone List
- zoj 2876 Phone List
- 字典树phone list
- Phone List(字典树)
- Phone List(字典树)
- Phone List --->字典树
- ZOJ 2876 Phone List(trie树)
- zoj 2876 Phone List(tire 树)
- 【字典树】zoj2876 Phone list
- 【字典树】 hdu1671 Phone List
- poj3630(Phone List+字典树)
- Phone List(poj3630,字典树)
- Phone List(hdu1671字典树)
- hdu1671 Phone List (字典树)
- hdu Phone List 字典树
- HDU1671 Phone List【字典树】
- VC6编译卡死之解决办法
- 就是一个尿素
- 工作手记(二)
- 在web中上传文件
- 开发环境的小见解
- zoj 2876 Phone List【字典树】【水】
- 将django的HTTP响应保存为excel
- Reading notes about low-resolution timer implementation on linux.
- Flashcache使用的误区以及解决方案
- SKB_BUFF整理笔记
- GSM网络中的一些基本概念(仅一些基本的术语)
- 杭电 3836 多校联合赛 强连通分量
- arduino
- List排序总结