随笔分类 - 字典树
摘要:题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1298/*字典树Date: 2012/11/1先用字典树存放单词,然后通过数字字符串枚举选择权值最大的那个单词即可注意枚举的时候要剪枝,不过也是很简单的剪枝*/#include<iostream>using namespace std;#define maxn 101struct Trie{ int n; Trie *next[26]; Trie() { n = 0; memset(next,0,sizeof(next)); }};int...
阅读全文
摘要:题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1800思路:仔细分析容易发现,其实就是求给定的字符串中出现最多的字符串个数,当用字符串实现时,注意前导0需去掉。方法一:map 这里为什么用map<int,int>可以,我想可能是因为虽然有的数超出范围但是读入的时候还是会读出一个数的(虽然这个数不是原来的那个数),而每个数都唯一,让然用map<string,int>似乎更合乎情理#include<stdio.h> #include<iostream>#include<map> usin
阅读全文
摘要:题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1671动态分配内存,当实例较多时需释放内存,不然会超空间#include<iostream>#include<string>#include<cstdio>using namespace std;#define maxn 10001char s[maxn][11];struct Trie{ Trie *next[10]; Trie() { memset(next,0,sizeof(next)); }};void Insert(Trie *root,char .
阅读全文
摘要:方法一:字典树515ms#include<iostream>#include<string>using namespace std;struct Trie{ string s; //在每个单词的末尾节点上保存该单词的英语意思 Trie *next[26]; Trie() { s = ""; memset(next,0,sizeof(next)); }};void Insert(Trie *root,string s1,string s2){ Trie *p = root; for(int i = 0; i < s2.si...
阅读全文
摘要:/*Date: 2012/10/27题目链接地址:http://acm.hdu.edu.cn/showproblem.php?pid=1247思路:把字典中的每个字符串拆成0->j 和 j->n 两个子串,再分别查找这两个子串 在不在字典中,若在则满足题意*/方法1:字典树#include<iostream>#include<string>using namespace std;#define maxn 50001string s[maxn];struct Trie{ int n; Trie *next[26]; Trie() { n = 0; ...
阅读全文

浙公网安备 33010602011771号