题目链接:https://vjudge.net/problem/HDU-1247

题意:给定n个字符串(n<=50000),判断其中哪些字符串恰能由另外两个不同的字符串连接而成。

思路:

  暴力字典树即可。右n个字符串建树,然后把每个字符串拆分判断两部分是否都在树中。

AC code:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; const int maxn=;
const int maxm=1e6+;
int n,trie[maxm][],key[maxm],cnt;
char str[maxn][]; void insert(char *s){
int len=strlen(s),u=;
for(int i=;i<len;++i){
int t=s[i]-'a';
if(!trie[u][t]){
++cnt;
memset(trie[cnt],,sizeof(trie[cnt]));
key[cnt]=;
trie[u][t]=cnt;
}
u=trie[u][t];
if(i==len-) key[u]=;
}
} bool query(int k,int l,int r){
int u=;
for(int i=l;i<=r;++i){
int t=str[k][i]-'a';
if(!trie[u][t]) return false;
u=trie[u][t];
}
if(!key[u]) return false;
else return true;
} int main(){
memset(trie[],,sizeof(trie[]));
while(~scanf("%s",str[++n])){
insert(str[n]);
}
--n;
for(int i=;i<=n;++i){
int flag=,len=strlen(str[i]);
for(int j=;j<=len-;++j)
if(query(i,,j-)&&query(i,j,len-)){
flag=;
break;
}
if(flag) printf("%s\n",str[i]);
}
return ;
}

最新文章

  1. Lucene4.1 视频学习
  2. 一篇让Java程序猿随时可以翻看的Oracle总结
  3. 基于淘宝开源Tair分布式KV存储引擎的整合部署
  4. Inside TSQL Querying - Chapter 1. Logical Query Processing
  5. LinkedHashMap介绍
  6. saltstack实战4--综合练习1
  7. ▲▲▲▲▲▲▲▲▲▲▲yum源的配置(本地和ftp)▲▲▲▲▲▲▲▲▲▲▲▲▲v
  8. GCC(警告.优化以及调试选项)
  9. JavaScript路线
  10. Visual Studio 2017的安装与使用
  11. 面试题07_用两个栈实现队列——剑指offer系列
  12. EXCEPTION:FATAL: UNABLE TO CREATE ‘…GIT/INDEX.LOCK’ FILE EXISTS
  13. K好数
  14. eclipse git 报 git: 401 Unauthorized
  15. Angular material mat-icon 资源参考_Editor
  16. Vue-cli 工具 / 通过 Vue-cli 工具重构 todoList
  17. 详解Python中的生成器表达式(generator expression)
  18. C语言进阶——变量属性05
  19. php中各种操作字符串和时间戳的代码关键词
  20. 关于Banner设计的促销氛围

热门文章

  1. 【一起来烧脑】读懂HTTP知识体系
  2. Matlab中画图数学公式的输出格式
  3. synology git 服务器问题处理
  4. 获取句柄的类型以及对应的ID序号
  5. Spring MVC国际化配置
  6. ES6中的class类的理解
  7. Spring boot Bean装配
  8. T-MAX-测试总结
  9. C# 复制数组容易踩到的坑--引用类型与值类型
  10. Mysql sql_mode设置 timestamp default 0000-00-00 00:00:00 创建表失败处理