hdu 1277 全文检索 (字典树应用)
全文检索
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2553 Accepted Submission(s): 853
问题的描述是这样的:给定一个信息流文件,信息完全有数字组成,数字个数不超过60000个,但也不少于60个;再给定一个关键字集合,其中关键字个数不超过10000个,每个关键字的信息数字不超过60个,但也不少于5个;两个不同的关键字的前4个数字是不相同的;由于流文件太长,已经把它分成多行;请你编写一个程序检索出有那些关键字在文件中出现过。
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
using namespace std;
int tree[][], vis[];
int id, root, len, n, m, num = , flag = , k = ;
string s;
char str[]; void insert(int cnt)
{
root = ;
for (int i = ; s[i]; i++)//如果用strlen()求长度会超时
{
id = s[i] - '';
if (!tree[root][id])
tree[root][id] = ++num;
root = tree[root][id];
}
vis[root] = cnt;
}
void search(char ss[])
{
root = ;
for (int i = ; i < ss[i]; i++)
{
id = ss[i] - '';
if (root&&vis[root])
{
if (flag == )
{
cout << "Found key:";
flag = ;
}
cout << " [Key No. " << vis[root] << ']';
vis[root] = ;//避免重复检索
}
if (!tree[root][id])
return;
root = tree[root][id];
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m;
while (n--)
{
string temp;
cin >> temp;
for (int i = ; i < temp.length(); i++)//文本合并
str[k++] = temp[i];
} for (int i = ; i <= m; i++)
{
string temp;
cin >> temp >> temp >> temp >> s;//cin遇到空格停止
insert(i);
}
for(int i=;str[i];i++)//依次变化起始匹配位置
search(str+i);
if (flag == )
cout << "No key can be found !" << endl;
else
cout<<endl;
return ;
}
hdu 1277 全文检索 (字典树应用)的更多相关文章
- hdu 1277 全文检索
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1277 全文检索 Description 我们大家经常用google检索信息,但是检索信息的程序是很困难 ...
- hdu 1979 DFS + 字典树剪枝
http://acm.hdu.edu.cn/showproblem.php?pid=1979 Fill the blanks Time Limit: 3000/1000 MS (Java/Others ...
- hdu 2846(字典树)
Repository Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- HDU 2846 Repository (字典树 后缀建树)
Repository Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- HDU 1671 (字典树统计是否有前缀)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671 Problem Description Given a list of phone number ...
- HDU 2846 Repository(字典树,标记)
题目 字典树,注意初始化的位置~!!位置放错,永远也到不了终点了org.... 我是用数组模拟的字典树,这就要注意内存开多少了,,要开的不大不小刚刚好真的不容易啊.... 我用了val来标记是否是同一 ...
- *hdu 5536(字典树的运用)
Input The first line of input contains an integer T indicating the total number of test cases. The f ...
- three arrays HDU - 6625 (字典树)
three arrays \[ Time Limit: 2500 ms \quad Memory Limit: 262144 kB \] 题意 给出 \(a\),\(b\) 数组,定义数组 \(c[i ...
- HDU 6625 (01字典树)
题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中: ...
随机推荐
- SAP BO WebI 如何连接webi server folder下面的EXCEL文件作为数据源
昨天做Webi Report,需要连接一个在Webi Server Folder下面的EXCEL文件作为数据源,然后再去生成相应的报表,找了半天才找到可以连接Webi Server Folder的EX ...
- Java Hashtable遍历与方法使用
参考文档 我参考了Java 集合系列11之 Hashtable详细介绍(源码解析)和使用示例,阅读了jdk 1.8的源码 Hashtable的继承关系 Hashtable继承了Dictionary类, ...
- java第二次课件课后动手动脑习题整理总结(2019年9月23号)
一.动手动脑 1 1.题目 2.程序源代码 package yang8; import java.util.Scanner; import java.util.Random; public class ...
- 标准模板库中的链表(list)
//C++数据结构与算法(第4版) Adam Drozdek 著 徐丹 吴伟敏<<清华大学出版社>> 头文件:include<list> list() 创建一个 ...
- VUE 使用axios请求第三方接口数据跨域问题解决
VUE是基于node.js,所以解决跨域问题,设置一下反向代理即可. 我这里要调用的第三方接口地址为 http://v.juhe.cn/toutiao/index?type=top&key=1 ...
- redis api-String
- mutiset的简单介绍转载
原文链接:https://blog.csdn.net/sodacoco/article/details/84798621 c++语言中,multiset是<set>库中一个非 ...
- 「LuoguP3979」遥远的国度
传送门 Luogu 解题思路 带换根操作的树剖. 换根只会影响更新或查询子树信息的操作. 我们始终保持初始的根不变,然后只要分类讨论一下: 假设当前被查询的节点是 \(u\) 如果 \(u\) 就是根 ...
- 5G/NR 波束管理
原文链接:http://www.sharetechnote.com/html/5G/5G_Phy_BeamManagement.html 1 为什么光束管理/光束控制? 我不认为高频部署中的波束传输信 ...
- C++中的简单继承
Father.cpp: #include<iostream> using namespace std; class Father { protected: int width; int h ...