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; } ```
查看全文
相关阅读:
ASCII,Unicode 和 UTF-8
ASCII,Unicode 和 UTF-8
043_JVM——JVM是什么鬼啊?他与操作系统是什么关系?
042_杂谈——编程语言的发展
042_线程——我们写的代码,为什么我从来没有线程呢?
041_ssm——/与/*与*.do的区别?
040_HTTP——为什么会有get与post两种请求?
039_Servlet——SpringMVC中怎么不见Servlet呢?我们写的Controller都是普通类,Servlet藏到了那里?
038_JVM——怎么查看对象的内存大小?
037_JVM——java中的类加载器是怎么运行的?
原文地址:https://www.cnblogs.com/orangee/p/8913065.html
最新文章
15. JSP 过滤器
6.BootStrap 内容排版
Mysql调试存储过程最简单的方法
MySQL中delimiter关键字的使用
mysql partitions by range auto (mysql 自动创建按年月的表分区)
mysql 5.7版本 最大分区数目_面对亿量级数据,除了分库分表,Mysql分区表你也应该了解一下...
MySQL Event
mysql之自定义函数
Mysql自动按月表分区
MySQL 获取本月第一天、下个月第一天等
热门文章
查看mysql 某张表的分区情况
mysql表分区详解
StringBuffer、StringBuilder与为什么说StringBuilder是不安全的
StringBuffer、StringBuilder与为什么说StringBuilder是不安全的
玩转Java对象和XML相互转换
玩转Java对象和XML相互转换
Thinking in java(七)
Thinking in java(七)
Thinking in java(六)
Thinking in java(六)
Copyright © 2011-2022 走看看