标签:strlen %s insert nod main bre node 阅读 bool
原题链接:[TJOJ2010]阅读理解
给你很多个字符串,再给你单个字符串,问后面单个字符串是否在前面多个字符串中出现过
很简单..不用我多说 2 3分钟写完
但是!我交了20多遍,为什么?
TM它卡bool(草
这道题让我理解了什么叫\(bitset\),以后就不用bool了 quq
//#define fre yes
#include <bitset>
#include <cstdio>
#include <cstring>
const int N = 600010;
struct Node {
int son[26];
} trie[N];
std::bitset<1001> b[500007];
int tnt;
void trieInsert(char c[], int k) {
int len = strlen(c + 1);
int rt = 0;
for (int i = 1; i <= len; i++) {
int id = c[i] - 'a';
if(!trie[rt].son[id]) trie[rt].son[id] = ++tnt;
rt = trie[rt].son[id];
} b[rt][k] = 1;
}
int n;
void trieFind(char c[]) {
int len = strlen(c + 1);
int flag = 1, rt = 0;
for (int i = 1; i <= len; i++) {
int id = c[i] - 'a';
if(!trie[rt].son[id]) {
flag = 0;
break;
} rt = trie[rt].son[id];
} if(flag) {
for (int i = 1; i <= n; i++) {
if(b[rt][i]) {
printf("%d ", i);
}
}
} puts("");
}
char c[10000];
int main() {
static int m;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
for (int j = 1; j <= x; j++) {
scanf("%s", c + 1);
trieInsert(c, i);
}
}
scanf("%d", &m);
for (int i = 1; i <= m; i++) {
scanf("%s", c + 1);
trieFind(c);
} return 0;
}
标签:strlen %s insert nod main bre node 阅读 bool
原文地址:https://www.cnblogs.com/Nicoppa/p/11509862.html