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; } ```
查看全文
相关阅读:
C# Unity依赖注入
Spring学习总结
.Net 上传文件和下载文件
JavaWeb学习篇--Filter过滤器
Struts2入门教程
Ceph 时钟偏移问题 clock skew detected 解决方案--- 部署内网NTP服务
Erasure Coding(纠删码)深入分析 转
s3cmd : Add a config parameter to enable path-style bucket access 当ceph rgw使用域名时,需要支持 path-style bucket特性
ceph rgw java sdk 使用域名访问服务时需要设置s3client的配置项 PathStyleAccess 为true, 负责将报域名异常
直播流怎么存储在Ceph对象存储上? Linux内存文件系统tmpfs(/dev/shm) 的应用
原文地址:https://www.cnblogs.com/orangee/p/8913065.html
最新文章
旋转测试
getRectSubPix函数
matlab 修改文件夹下所有文件名大写为小写
ntp时间服务
写一个函数封装printf用作trace
sobel 使用说明
vm克隆linux系统 后连接网络
一段javascript设计模式应用场景
Table 'hd_online' is marked as crashed and should be repaired索引损坏
忘记原来的myql的root的密码;
热门文章
在线时长缓存
lnmp配置信息 4核8g优化
linux 配置信息
国盛聊天直播室,一点点觉悟。
UNIX域套接字连接mysql
Oracle数据库基础教程
C# NPOI生成Excel文档(简单样式)
.Net MVC 获取Response和Request对象
Linq的常见查询
C# 反射常见用法
Copyright © 2011-2022 走看看