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中: ...
随机推荐
- java 外卖店优先级
[问题描述] “饱了么”外卖系统中维护着 N 家外卖店,编号 1 ∼ N.每家外卖店都有 一个优先级,初始时 (0 时刻) 优先级都为 0. 每经过 1 个时间单位,如果外卖店没有订单,则优先级会减少 ...
- 报错google.protobuf.text_format.ParseError: 166:8 : Message type "object_detection.protos.RandomHorizontalFlip" has no field named "i".解决方法
运行python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_ ...
- 02-02Android 学习进度报告二
今天我主要学习了Android的UI基础布局知识,主要是学习View与ViewGroup的概念以及其区别. 首先是代码说明: <?xml version="1.0" enco ...
- oracle练习-day03
.创建表空间.创建用户赋权限.创建表语法:.常见的数据类型字符 myname ) varchar2:推荐使用这个 可变长度最大字符 myname varchar2() 字 ...
- n/20 文本框动态监听输入长度
- Spring框架中的JDK与CGLib动态代理
JDK和CGLib动态代理区别 JDK动态代理:利用拦截器(拦截器必须实现InvocationHanlder)加上反射机制生成一个实现代理接口的匿名类, 在调用具体方法前调用InvokeHandler ...
- Jquery选择器大全汇总
一.选择器 1.三个基本选择器,$("#ID") .$(".className") .$("tagName") 2.其他选择器 //htm ...
- liunx命令用到的
su:切换成root用户 sudo su:普通用户申请root权限 ping命令可以检查linux是否联网 ping www.baidu.com 如图就是联网了 结束ping包括其他linux的指令 ...
- crackme---攻防世界
首先下载附件之后,查壳 虽然什么也没有发现,但是看一下区段就知道,这个是北斗的壳.所以我们首先载入od开始把壳脱掉 这里面也可以看到pushfd和pushad是北斗壳的特征 这里面我使用是esp定律脱 ...
- 使用BP拦截POST型请求包
1.安装phpstudy并下载wordpress 文件,安装在phpstudy的www目录下 phpstudy下载地址:https://www.xp.cn/download.html wordpres ...