当前位置:网站首页>字典树简单入门题(居然是蓝题?)
字典树简单入门题(居然是蓝题?)
2022-07-05 20:54:00 【汤键.TJ】
[TJOI2010] 阅读理解
题目描述
英语老师留了 N N N 篇阅读理解作业,但是每篇英文短文都有很多生词需要查字典,为了节约时间,现在要做个统计,算一算某些生词都在哪几篇短文中出现过。
输入格式
第一行为整数 N N N ,表示短文篇数,其中每篇短文只含空格和小写字母。
按下来的 N N N 行,每行描述一篇短文。每行的开头是一个整数 L L L ,表示这篇短文由 L L L 个单词组成。
接下来是 L L L 个单词,单词之间用一个空格分隔。
然后为一个整数 M M M ,表示要做几次询问。后面有 M M M 行,每行表示一个要统计的生词。
输出格式
对于每个生词输出一行,统计其在哪几篇短文中出现过,并按从小到大输出短文的序号,序号不应有重复,序号之间用一个空格隔开(注意第一个序号的前面和最后一个序号的后面不应有空格)。如果该单词一直没出现过,则输出一个空行。
样例 #1
样例输入 #1
3
9 you are a good boy ha ha o yeah
13 o my god you like bleach naruto one piece and so do i
11 but i do not think you will get all the points
5
you
i
o
all
naruto
样例输出 #1
1 2 3
2 3
1 2
3
2
提示
对于 30 % 30\% 30% 的数据, 1 ≤ M ≤ 1 0 3 1\le M\le 10^3 1≤M≤103 。
对于 100 % 100\% 100% 的数据, 1 ≤ M ≤ 1 0 4 1\le M\le 10^4 1≤M≤104, 1 ≤ N ≤ 1 0 3 1\le N\le 10^3 1≤N≤103 。
每篇短文长度(含相邻单词之间的空格) ≤ 5 × 1 0 3 \le 5\times 10^3 ≤5×103 字符,每个单词长度 ≤ 20 \le 20 ≤20 字符。
每个测试点时限 2 2 2 秒。
所有过程都在注释里
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
typedef long long ll;
int son[N][30],idx,n,l,m;
char a[N];
bitset<1010> sign[N];
// 用bool会爆空间
// 用bool一个值占1字节,1个字节是8比特
// 用bitset则每个bool值只占用一个比特,大大节省空间
void insert(char str[],int k){
//插入字符串,同时告知是哪行
int p=0; //从根节点开始遍历插入
int l=strlen(str);
for(int i=0;i<l;i++){
int u=str[i]-'a'; // 方便当作下标
if(!son[p][u]) son[p][u]=++idx;
//查看当前节点p的子节点u是否已给予编号,没有则标记给予编号
p=son[p][u];//移至下一节点转换位置
}
sign[p][k]=1;//标记该字符串存在于第k行
}
void find(char str[]){
//查找该字符串
int p=0,signsign=1;//初始化,回到根节点继续查
int l=strlen(str);
for(int i=0;i<l;i++){
//遍历节点进行查询
int u=str[i]-'a';
if(!son[p][u]){
//一旦发现未被标记,则不存在该字符串,退出遍历查询
signsign=0;//同时标记不存在
break;
}
p=son[p][u];//移至下一节点转换位置
}
if(signsign){
//通过标记判断是否查询成功
for(int i=1;i<=n;i++){
if(sign[p][i]){
//通过标记查看此行是否存在此字符串
printf("%d ",i);
}
}printf("\n");
}
else{
puts("");
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>l;
for(int j=1;j<=l;j++){
scanf("%s",a);
insert(a,i);
}
}
cin>>m;
for(int i=1;i<=m;i++){
scanf("%s",a);
find(a);
}
return 0;
}
边栏推荐
- Implementation of redis unique ID generator
- 判断横竖屏的最佳实现
- 《SAS编程和数据挖掘商业案例》学习笔记# 19
- 重上吹麻滩——段芝堂创始人翟立冬游记
- Analyze the knowledge transfer and sharing spirit of maker Education
- 示波器探头对信号源阻抗的影响
- POJ 3414 pots (bfs+ clues)
- 科普|英语不好对NPDP考试有影响吗 ?
- Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
- How to renew NPDP? Here comes the operation guide!
猜你喜欢
Abbkine trakine F-actin Staining Kit (green fluorescence) scheme
Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
Abnova blood total nucleic acid purification kit pre installed relevant instructions
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
Abbkine BCA法 蛋白质定量试剂盒说明书
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
Abnova丨荧光染料 620-M 链霉亲和素方案
实现浏览页面时校验用户是否已经完成登录的功能
Specification of protein quantitative kit for abbkine BCA method
浅聊我和一些编程语言的缘分
随机推荐
实现浏览页面时校验用户是否已经完成登录的功能
Abnova丨 MaxPab 小鼠源多克隆抗体解决方案
Duchefa p1001 plant agar Chinese and English instructions
Which is the best online collaboration product? Microsoft loop, notion, flowus
[quick start of Digital IC Verification] 2. Through an example of SOC project, understand the architecture of SOC and explore the design process of digital system
Norgen AAV extractant box instructions (including features)
poj 3414 Pots (bfs+线索)
AI 从代码中自动生成注释文档
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
Abnova fluorescent dye 620-m streptavidin scheme
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
科普|英语不好对NPDP考试有影响吗 ?
Is Kai Niu 2980 useful? Is it safe to open an account
Abnova CD81 monoclonal antibody related parameters and Applications
Prosci LAG-3 recombinant protein specification
Duchefa d5124 md5a medium Chinese and English instructions
基于AVFoundation实现视频录制的两种方式
挖财商学院给的证券账户安全吗?可以开户吗?
Is it necessary for bazel to learn