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; } ```
查看全文
相关阅读:
Memoization-329. Longest Increasing Path in a Matrix
Map-560. Subarray Sum Equals K
Geometry-587. Erect the Fence
Reservoir Sampling-382. Linked List Random Node
Brainteaser-292. Nim Game
Minimax-486. Predict the Winner
Topological Sor-207. Course Schedule
web前端开发规范手册
css初始化
asp.net LINQ实现数据分页
原文地址:https://www.cnblogs.com/orangee/p/8913065.html
最新文章
【Network Architecture】Densely Connected Convolutional Networks 论文解析
【网络结构】MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications论文解析
【Network architecture】Rethinking the Inception Architecture for Computer Vision(inception-v3)论文解析
【Semantic segmentation】Fully Convolutional Networks for Semantic Segmentation 论文解析
【网络结构】Deep Residual Learning for Image Recognition(ResNet) 论文解析
【网络优化】Batch Normalization(inception V2) 论文解析(转)
【网络结构可视化】Visualizing and Understanding Convolutional Networks(ZF-Net) 论文解析
jQuery中的表单过滤选择器(四、七)::input、:text、:password、:radio、:checkbox、:file等
jQuery中的子(后代)元素过滤选择器(四、六):nth-child()、first-child、last-child、only-child
jQuery中的属性过滤选择器(四、五):[attribute] 、[attribute=value]、[attribute!=value] 、[attribute^=value] 等
热门文章
jQuery中的内容、可见性过滤选择器(四、四)::contains()、:empty、:has()、:parent、:hidden、:visible
jQuery中的基本过滤选择器(四、三)::first、:last、:not() ... ...
jQuery中的层级选择器(四、二):后代元素、子元素、相邻元素、兄弟元素
jQuery中的基本选择器(四、一):* 、 . 、element(直接标签名)、 或者用逗号隔开跟多个
jQuery中ajax请求的六种方法(三、六):load()方法
jQuery中ajax请求的六种方法(三、五):$.getScript()方法
jQuery中ajax请求的六种方法(三、四):$.getJSON()方法
web前端学习路线
深度优先算法+广度优先算法
编译原理
Copyright © 2011-2022 走看看