zoukankan
html css js c++ java
Codeforces 514 D R2D2 and Droid Army(Trie树)
[题目链接](http://codeforces.com/problemset/problem/514/D) 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串。 关于字符串查询的题,可以用[字典树(Trie树)](http://www.cnblogs.com/orangee/p/8912971.html)来解,第一次接触,做个小记。在查询时按题目要求进行查询。 代码: ```C++ #define _CRT_SECURE_NO_DEPRECATE #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; typedef long long ll; typedef pair
P; typedef map
M; typedef vector
V; typedef queue
Q; const int maxn = 6 * 100000 + 10; const int N = 3; struct trie { trie* next[N]; int count; }; typedef trie* link; link create() { link p = new trie; p->count = 0; for (int i = 0; i < N; ++i) p->next[i] = NULL; return p; } void insert(char* s, link root) { char* p = s; link node = root; while (*p) { if (node->next[*p - 'a']==NULL) node->next[*p - 'a'] = create(); node = node->next[*p - 'a']; ++p; } node->count++; return; } bool query(char* s, link pos,int cnt) { if (*s == ' ') { if (cnt == 1 && pos->count) return true; else return false; } for (int i = 0; i < N; ++i) { if (i != *s - 'a' && cnt==0 && pos->next[i]) { if (query(s + 1, pos->next[i], 1)) return true; } if (i == *s - 'a' && pos->next[i]) { if (query(s + 1, pos->next[i], cnt)) return true; } } return false; } char s[maxn]; int main() { int n,m,k,i,j; link root=create(); cin >> n >> m; for (i = 0; i < n; ++i) { scanf("%s", s); insert(s, root); } for (i = 0; i < m; ++i) { scanf("%s", s); if (query(s, root, 0)) cout << "YES "; else cout << "NO "; } return 0; } ```
查看全文
相关阅读:
LoadRunner脚本关联动态数据的最简单方法
LoadRunner 检查点函数总结
算法(一)时间复杂度
JAVA虚拟机总结
java8中Lambda表达式和Stream API
算法总结
listview 异步加载图片并防止错位
Java设计模式菜鸟系列(一)策略模式建模与实现
Python基础--webbrowser
Shiro学习(22)集成验证码
原文地址:https://www.cnblogs.com/orangee/p/8913065.html
最新文章
作为华人首富,李嘉诚为什么负债率只有2.7%,只因他坚持一个理念
是什么让并未受到很多专业教育的李嘉诚创造了今天的商业奇迹?
Xamarin iOS教程之页面控件
『干货』分享你最喜欢的技巧和提示(Xcode,objective-c,swift,c...等等)
分布式数据库集群中间件
安卓系统下的多线程断点下载实现
2.缓存机制
Unity3d的批渲染 batch rendering
cc2540 usbdongle 安装驱动失败的终极解决方法 【原创,多图】
自然语言处理中的Attention Model:是什么及为什么
热门文章
解决华为手机不出现logcat日志的问题
纯CSS实现移动端常见布局——高度和宽度挂钩的秘密
【VMware虚拟化解决方案】配置和部署VMware ESXi5.5
IP欺骗:要虚拟很多IP的情况:在一台机上虚拟的IP跨网段的处理,可通过在服务器端添加路由来实现
启动ip wizard时报the ip wizard does not support dhcp
性能测试中设置思考时间的作用
LoadRunner常见问题整理
LR基础学习_脚本信息函数
关于LoadRunner的迭代
Loadrunner脚本回放 场景运行过程中常见错误分析
Copyright © 2011-2022 走看看