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 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 == '\0')
{
if (cnt == 1 && pos->count)
return true;
else
return false;
}
for (int i = 0; i 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
Codeforces 514 D R2D2 and Droid Army(Trie树)的更多相关文章
- Codeforces 514 D R2D2 and Droid Army(RMQ+二分法)
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, w ...
- Codeforces Round #291 (Div. 2) D. R2D2 and Droid Army [线段树+线性扫一遍]
传送门 D. R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- 【codeforces 514D】R2D2 and Droid Army
[题目链接]:http://codeforces.com/contest/514/problem/D [题意] 给你每个机器人的m种属性p1..pm 然后r2d2每次可以选择m种属性中的一种,进行一次 ...
- R2D2 and Droid Army(多棵线段树)
R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 861D - Polycarp's phone book 【Trie树】
<题目链接> 题目大意: 输入7e4个长度为9的字符串,每个字符串中只出现0~9这几种数字,现在需要你输出每个母串中最短的特有子串. 解题分析: 利用Trie树进行公共子串的判定,因为Tr ...
- 【Cf #291 B】R2D2 and Droid Army(二分,线段树)
因为题目中要求使连续死亡的机器人最多,令人联想到二分答案. 考虑如何检验这之中是否存在一段连续的长度为md的区间,其中花最多k步使得它们都死亡. 这个条件等价于区间中m个最大值的和不超过k. 枚举起点 ...
- Codeforces 633C Spy Syndrome 2(DP + Trie树)
题目大概说给一个加密的字符串,加密规则是把原文转化成小写字母,然后各个单词反转,最后去掉空格.现在给几个已知的单词,还原加密的字符串. 和UVa1401一个道理.. 用dp[i]表示加密字符前i个字符 ...
- trie树 Codeforces Round #367 D Vasiliy's Multiset
// trie树 Codeforces Round #367 D Vasiliy's Multiset // 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值 / ...
- Codeforces 633C Spy Syndrome 2 | Trie树裸题
Codeforces 633C Spy Syndrome 2 | Trie树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已 ...
随机推荐
- Java多线程(一):线程与进程
1.线程和进程 1.1 进程 进程是操作系统的概念,我们运行的一个TIM.exe就是一个进程. 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位 ...
- lua的数据类型
Lua 是动态(弱)类型的语言,它有一下几种数据结构: nil(空) nil 类型表示一种没有任何有效值,它只有一个值 -- nil,例如打印一个没有赋值的变量,便会输出一个 nil 值: print ...
- c# 多线程使用队列顺序写日志的类 (需要再优化)
using System; using System.Collections.Generic; using System.Threading; public class LogManager { // ...
- 【原创】大叔问题定位分享(34)Spring的RestTemplate请求json数据后内容被修改
先看代码 org.springframework.web.client.RestTemplate public RestTemplate() { this.messageConverters = ne ...
- LeetCode:181.超过经理收入的员工
题目链接:https://leetcode-cn.com/problems/employees-earning-more-than-their-managers/ 题目 Employee 表包含所有员 ...
- promise使用的正确方式
一开始恨不能理解下面的代码,为什么可以一直then下去,什么时候要直接return xxx,什么时候return 一个promise,什么时候用Promise.resolve() function ...
- 转:git上传本地项目到github
转自:https://blog.csdn.net/Lucky_LXG/article/details/77849212 将本地项目上传到Github(两种简单.方便的方法) 一.第一种方法:首先你需要 ...
- tp中的u方法
个人总结以免忘记 在模板中的使用{:U('地址', '参数'…)} <!--在模板中使用U方法 --> <a href="{:U('News/index')}" ...
- css中animation和@keyframes 动画
Animation 使用简写属性,将动画与 div 元素绑定: div { animation:mymove 5s infinite; -webkit-animation:mymove 5s infi ...
- 微信小程序下拉刷新
<config> { enablePullDownRefresh: true, navigationBarTitleText: "消息中心", } </confi ...