随笔分类 - trie 字典树
摘要:比赛那天下午做的。。。比赛的时候真不知道怎么做。。。亏了没做,做了我就死了。。欧拉回路我是真心不会判断啊(真的是忘了)。。。虽然离散考了86(鼓掌~),也不过是全班最高(再次鼓掌~)但是真的是恶补出来的(天赋秉异,美女上台献花)不扯淡了。。。这道题因为数据量比较大。。。500000的数据,所以用map和平常的查找肯定会TLE所以,要用到TRIE树。然后欧拉通路的判定就是通过查找度数为奇数的节点 < 2 是否成立不成立肯定是错的,但是成立了也要判断是不是父节点是否为一个节点。比如red redblue blue答案就是impossible代码如下View Code 1 #include &
阅读全文
摘要:题目连接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1500大意:输入几个字符串,然后再输入几个字符串,看第一次输入的字符串有多少没有在后面的字符串中出现(后输入的字符串不一定出现在之前的字符串中)代码:View Code 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 struct node 5 { 6 int flag; 7 struct node *next[2
阅读全文
摘要:题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1075大意:有外星人来了,但是我不懂外星文。然后我有一本字典,然我去翻译,字典由start开始有end结束的相当于map转换,然后是由由start开始有end结束的需要翻译的句子。代码#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>typedef struct node{ int flag; char ans[55]; struct node *next
阅读全文
摘要:这道题我用得静态树,发现静态树不如动态树啊,虽然时间快点,但是空间要求的也太离谱了~题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1247大意:让你输入几个单词,然后看看这有几个是可以有其他的任意两个单词或者一个单词两次,连接组成的,把他们输出就可以了代码View Code 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 const int N=26; 5 const int maxn=1000000; 6 char s[5000
阅读全文
摘要:典型的字典树使用一个flag来标记是否是一个句子。现在我们可以用一个cout来标记这条路径是否有单词存在过,存在过几次连接http://poj.org/problem?id=2001View Code #include <iostream>#include<stdio.h>#include<stdlib.h>#include<string.h>using namespace std;struct node{ int count;//用来存有多少个单词存在过。 int next[27];}word[20100];int num = 0;char s
阅读全文
摘要:跟那个排序二叉树的那个静态树一样,不大习惯静态的,但是不静态会tle,94msView Code #include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct node{ int flag; int next[11];}trie;int leap,count;trie tr[100010];new_node(){ int i; count++; tr[count].flag = 0; for(i = 0;i < 10;i++) tr[count].next[i] ...
阅读全文

浙公网安备 33010602011771号