POJ2503(Babelfish)--简单字典树】的更多相关文章

思路:就是用一个字典树翻译单词的问题,我们用题目中给出的看不懂的那些单词建树,这样到每个单词的叶子结点中存放原来对应的单词就好. 这样查询到某个单词时输出叶子结点存的就行,查不到就"en"呗.这题用hash也是可以的 #include<iostream> #include<cstdio> #include<stdio.h> #include<cstring> #include<cmath> #include<vector…
Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30816   Accepted: 13283 Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have…
Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 29059 Accepted: 12565 Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary…
#include<stdio.h> #include<iostream> #include<string.h> using namespace std; struct node { int num,i; node *a[27]; node (){ num=0; for(i=0;i<27;i++) a[i]=NULL; } }*root; char str[20]; void insert(int len,node *root) { int i; node *q;…
题意:给一个字符串集,要你给出n个字符串s,使s能被所给字符串集中的两个相加所得(ahat=a+hat) 思路:简单字典树题,注意查询的时候要判断所指next是否为NULL,否则会RE非法访问. 代价: #include<cstdio> #include<cstring> #include<cstdlib> #include<queue> #include<cmath> #include<string> #include<sta…
因为字符集比较大,所以就不能用简单字典树,在字典树里面,用链表进行存储.这个倒是不难,练了下手 统计的时候还是有点难搞,因为要算所有的两两比较的次数之和,对分叉处进行计算,注意细节 #include <iostream> #include <cstdio> #include <cstring> using namespace std; *+; struct Trie { int head[N]; int next[N]; char ch[N]; int tot[N];…
题意:上部分是单词表,下部分是句子,翻译句子.START开始,END结束. 思路:简单字典树. Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to…
Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 35828   Accepted: 15320 Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have…
题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP 参考博客:POJ2503两种解法:快速排序+二分查找与哈希表 思路1:可以使用map来做 代码: #include<iostream> #include<stdio.h> #include<string> #include<map> using namespac…
传送门 题意: 给你一个初始串 S,strlen(s) <= 3e5  然后给你 n 个单词. n <= 4000,  每个单词的长度不超过 100 : 问你这个初始串,分割成若干个单词的连接的方案:(这些单词必须是给定的n个单词中的任意一个,一个单词可以被使用多次.) 解: 将 n 个单词建个字典树: dp[ i ] 表示,S的 0 ~ i - 1 切割成若干个 单词的方案数: 枚举S, 枚举到 当前位置 i: 然后就在字典树找,以 S 的 i + 1 开始的, 能不能找到一个单词与之匹配:…