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; } ```
查看全文
相关阅读:
#333 Div2 Problem B Approximating a Constant Range(尺取法)
苦逼的单身狗(玄乎的尺取大法)
欧拉项目第四题之三位数之积数的最大回数
欧拉项目第三题之最大质数因子
关于尺取法的认识与简单例题
codeforces 980B Marlin
康托展开和逆康托展开
Chrome控制台中Network的Preview与Response区别
配置Express中间件
Express中间件简介
原文地址:https://www.cnblogs.com/orangee/p/8913065.html
最新文章
Codevs 2875 RY哥查字典
Codevs
2014.6.14模拟赛【bzoj1646】[Usaco2007 Open]Catch That Cow 抓住那只牛
bzoj3403[Usaco2009 Open]Cow Line 直线上的牛
bzoj1433[ZJOI2009]假期的宿舍
bzoj1626[Usaco2007 Dec]Building Roads 修建道路
bzoj1083[SCOI2005]繁忙的都市
vijos1782借教室
bzoj1015[JSOI2008]星球大战starwar
bzoj1616[Usaco2008 Mar]Cow Travelling游荡的奶牛
热门文章
bzoj1699[Usaco2007 Jan]Balanced Lineup排队
bzoj2190[SDOI2008]仪仗队
bzoj3400[Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队
bzoj有趣的题目
bzoj1121[POI2008]激光发射器SZK
bzoj1660[Usaco2006 Nov]Bad Hair Day 乱发节
USACO月赛数据
超大背包
Codeforces Round #482 (Div. 2) C 、 Kuro and Walking Route(dfs)979C
Flowerpot(又是尺取。。)
Copyright © 2011-2022 走看看