【题目链接】:

https://loj.ac/problem/10049

【题意】

问是否存在一组公共前缀。如果存在输出“NO”,否则输出“YES”

【题解】

首先建出Trie树来,然后开始记录所有的字符串,然后进行再跑一遍。看看是否在跑的过程中遇到某个位置上标记。

裸的模板题。

【代码】

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e4 +;
int son[N*][];
bool cnt[N*],f;
int T,n,idx;
char str[N][];
void Insert(char s[]){
//printf("###%s\n",s);
int p = ;
for(int i= ; s[i] ; i++ ){
int t = s[i] - '';
if( !son[p][t] ) son[p][t] = ++idx ;
p = son[p][t];
}
cnt[p] = true;
}
void Query(char s[]){
//printf("$$$%s\n",s);
int p = ;
for(int i= ; s[i+] ; i++ ){
int t = s[i] - '';
if( !son[p][t] ) break;
p = son[p][t];
if( cnt[p] ) f = true;
}
}
void Init(){
f = false ;
idx = ;
memset(cnt,false,sizeof cnt );
memset(son,,sizeof son );
}
int main()
{
scanf("%d",&T);
while(T--){
Init();
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%s",str[i]);
Insert(str[i]);
}
for(int i=;i<=n;i++){
Query(str[i]);
}
puts(f?"NO":"YES");
}
return ;
}
/*
40
2
9999999999
999999999 2
9999999999
999999998 2
012
12 2
012
1 2
0
01 2
012
1 */

【Trie】Phone List的更多相关文章

  1. 【Trie】背单词

    参考博客: https://www.luogu.org/problemnew/solution/P3294 https://blog.csdn.net/VictoryCzt/article/detai ...

  2. 【Trie】L 语言

    [题目链接]: https://loj.ac/problem/10053 [题意]: 给出n个模式串.请问文本串是由多少个模式串组成的. [题解]: 当我学完AC自动机后,发现这个题目也太简单了吧. ...

  3. 【Trie】Nikitosh 和异或

    [参考博客]: LOJ#10051」「一本通 2.3 例 3」Nikitosh 和异或(Trie [题目链接]: https://loj.ac/problem/10051 [题意]: 找出两个不相交区 ...

  4. 【Trie】The XOR-longest Path

    [题目链接]: https://loj.ac/problem/10056 [题意] 请输出树上两个点的异或路径  的最大值. [题解] 这个题目,y总说过怎么做之后,简直就是醍醐灌顶了. 我们知道Xo ...

  5. 【Trie】Secret Message 秘密信息

    [题目链接]: https://loj.ac/problem/10054 [题意] 我认为这个题目最难的是题意: 其实分了两种情况: 1.如果当前文本串匹配不完,那么答案的是:匹配过程中遇到的模式串结 ...

  6. 【Trie】Immediate Decodability

    [题目链接]: https://loj.ac/problem/10052 [题意]: 就是给一些串,是否存在两个串是相同前缀的. [题解] 模板题,不想解释了. [代码]: #include<c ...

  7. 【Trie】The XOR Largest Pair

    [题目链接] https://loj.ac/problem/10050 [题意] 给出n个数,其中取出两个数来,让其异或值最大. [题解] 经典的01字典树问题. 首先需要把01字典树建出来. 然后对 ...

  8. 【Trie】模板(动态指针,静态数组)

    摘自hackbuteer1 Trie树,又称单词查找树或键树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的 ...

  9. 【Trie】【HDU1247】【Hat’s Wordsfd2】

    题目大意: hat's word 的定义是字典中 恰好由另外两个单词连接起来的单词 给你一本字典,问有多少个hat's word,(字典按字典序给出) 单词数50000.. 初步思路: 单词分为前缀单 ...

随机推荐

  1. POJ 2486 Apple Tree ——(树型DP)

    题意是给出一棵树,每个点都有一个权值,从1开始,最多走k步,问能够经过的所有的点的权值和最大是多少(每个点的权值只能被累加一次). 考虑到一个点可以经过多次,设dp状态为dp[i][j][k],i表示 ...

  2. Golang 二维切片初始化

    package main import "fmt" func main() { // 方法0 row, column := 3, 4 var answer [][]int for ...

  3. Ubuntu下Nginx的安装和卸载

    环境是Ubuntu 16.04 安装: sudo apt-get update sudo apt-get install nginx 卸载: sudo apt-get --purge remove n ...

  4. PHP中部分宏应用

    1.字符串复制 ZVAL_STRINGL(pzv, str, len, dup):str 和 len 分别为内存中保存的字符串地址和他的长度,dup之名该字符串是否需要被复制,值为1则将先申请一块新内 ...

  5. intellj idea 常用快捷键

    1.command+shift+a 查找操作2.command+e 查找历史打开的文件3.command+n 查找类4.command+shift+n 查找文件

  6. nodeJS 项目如何运行

    nodeJS 项目如何运行 一.总结 一句话总结: nodejs项目根目录中用node xx.js 或是 node xx运行 打开 window的 cmd 命令窗口,使用 cd 命令跳转到 nodeJ ...

  7. Bootstrap form-group and form-control

    https://github.com/twbs/bootstrap/blob/21f3375f21e9a7a5155d0cd783fd2bc7aeee8485/scss/_forms.scss htt ...

  8. Django module

    1,模型定义 models.py的例子: class Author(models.Model): name=models.CharField(max_length=20) class Book(mod ...

  9. Python 调用outlook发送邮件(转 )

    单账号: import win32com.client as win32 def send_mail(): outlook = win32.Dispatch('Outlook.Application' ...

  10. 003-多线程-JUC集合-Set-CopyOnWriteArrayList

    一.概述 它是线程安全的无序的集合,可以将它理解成线程安全的HashSet.有意思的是,CopyOnWriteArraySet和HashSet虽然都继承于共同的父类AbstractSet:但是,Has ...