Phone List HDU1671】的更多相关文章

#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cstdlib> using namespace std; template<int Size> struct trie_node{ bool terminable; //表示节点为字符串的结尾 int node; //子节点的个数 trie_node *child[Size]…
HDU1251:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题目大意:求得以该字符串为前缀的数目,注意输入格式就行了. #include<stdio.h> #include<string.h> ]; * ][], cnt; * ]; void insert() { int len = strlen(str); ; ; i < len; i ++) { int id = str[i] - 'a'; if(!trie[rt][id…
题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceeded: 前缀树是很费空间的数据结构,每个节点存放了字母(数字)个数个指针,正所谓用空间来换取时间. 我发现我忘记写析构函数了,所以测例多起来还不释放很容易超空间. 树形结构的析构也很有趣: ~Node() { ; i < ; ++i) { if (children[i]) { delete chil…
Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18421    Accepted Submission(s): 6207 Problem Description Given a list of phone numbers, determine if it is consistent in the sense tha…
Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10837    Accepted Submission(s): 3735 Problem Description Given a list of phone numbers, determine if it is consistent in the sense tha…
题目大意 给定一些电话号码,判断是否有电话号码是其他电话号码的前缀 题解 裸Trie树嘛~~~~只需要一个插入过程即可,假设X是Y的前缀,在插入的过程中有两种情况,X在Y之前插入,那么在插入Y的时候经过了X的尾结点,插入的过程中判断下即可,还有一种情况就是X在Y之后插入,那么插入X的时候肯定不需要插入新结点~~~也记录一下即可~~~~~被坑了好多次,先是没有考虑第二种情况,改了之后RE,然后脑残的发现把数字字符转换为数字的时候是-'a'-改完就AC了... 代码: #include <iostr…
Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7343    Accepted Submission(s): 2525 Problem Description Given a list of phone numbers, determine if it is consistent in the sense tha…
Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone…
字典树的包含与不包含关系 #include<bits/stdc++.h> using namespace std; ][]; ]; ; bool insert1( char *word ) { ; ;i<strlen(word);i++) { '; ) trie[root][ ch ]=++pos; &&root!=)return false; sum[root]=; root=trie[root][ch]; } ) sum[root]=; else return fal…
#include<cstdio> #include<cstdlib> #include<iostream> #include<cstring> #include<algorithm> using namespace std; ][],n,cnt; ]; ]; bool flag; void _insert() { ),tmp=; ;i<L;i++){ ']=++cnt; tmp=trie[tmp][c[i]-']; if(f[tmp]) f…