当前位置:网站首页>字典树简单入门题(居然是蓝题?)
字典树简单入门题(居然是蓝题?)
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;
}
边栏推荐
- Open source SPL eliminates tens of thousands of database intermediate tables
- 大二下个人发展小结
- Abnova CRISPR spcas9 polyclonal antibody protocol
- Use of thread pool
- haas506 2.0开发教程 - 阿里云ota - pac 固件升级(仅支持2.2以上版本)
- 如何让化工企业的ERP库存账目更准确
- Material design component - use bottomsheet to show extended content (II)
- 教你自己训练的pytorch模型转caffe(三)
- 示波器探头对测量带宽的影响
- Implementation of redis unique ID generator
猜你喜欢

When steam education enters personalized information technology courses

Abbkine BCA法 蛋白质定量试剂盒说明书
![最长摆动序列[贪心练习]](/img/e1/70dc21b924232c7e5e3da023a4bed2.png)
最长摆动序列[贪心练习]

Abnova fluorescent dye 620-m streptavidin scheme

Abnova丨血液总核酸纯化试剂盒预装相关说明书

实现浏览页面时校验用户是否已经完成登录的功能

教你自己训练的pytorch模型转caffe(三)
![[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](/img/1d/22bf47bfa30b9bdc2e8fd348180f49.png)
[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

How to make ERP inventory accounts of chemical enterprises more accurate

ClickHouse 复制粘贴多行sql语句报错
随机推荐
Abbkine BCA法 蛋白质定量试剂盒说明书
《SAS编程和数据挖掘商业案例》学习笔记# 19
当Steam教育进入个性化信息技术课程
教你自己训练的pytorch模型转caffe(一)
Write an interface based on flask
渗透创客精神文化转化的创客教育
Make Jar, Not War
Learning notes of SAS programming and data mining business case 19
ClickHouse 复制粘贴多行sql语句报错
leetcode:1755. 最接近目标值的子序列和
研学旅游实践教育的开展助力文旅产业发展
Is it safe to open a stock account by mobile phone? My home is relatively remote. Is there a better way to open an account?
Redis唯一ID生成器的实现
清除app data以及获取图标
Abnova丨 MaxPab 小鼠源多克隆抗体解决方案
Mode - "Richter replacement principle"
Use of thread pool
Return to blowing marshland -- travel notes of zhailidong, founder of duanzhitang
Duchefa丨低熔点琼脂糖 PPC中英文说明书
示波器探头对测量带宽的影响