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; } ```
查看全文
相关阅读:
python 读取邮件
windows 关于时间的计算
python 发送 smtp
常用HTML富文本编辑器
数据库设计:用户登录系统数据库表设计
在当前页面打开一个固定的窗口(页面):这种方式弹出来的窗口进行表单提交可更新父类窗口
后台模板
springboot/springmvc转换器
设计模式目录
组合条件分页查询
原文地址:https://www.cnblogs.com/orangee/p/8913065.html
最新文章
Web开发需要关注的技术细节
Linux Mono Asp.net 部署方案
现代Web的资源/类型/元素--发展趋势
redis使用心得
kafka的一些认识
软件工程中的依赖管理
那些年的网站负载技术
Cassandra中的数据一致性
REST建模语言RAML介绍
node访问iis使用keep-alive设置不当
热门文章
channel vs mutex
Golang下的Log处理
对Golang的一些看法
2、duilib 基本控件学习
1、duilib入门基础类CduiString
关于代码配置生成工具的软件
关于水表和物件溯源软件的总结
windows 核心编程第一章:关于错误
Layers 模式
最近的考勤跟称重项目总结
Copyright © 2011-2022 走看看