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树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已 ...
随机推荐
- flume收集日志直接sink到oracle数据库
因为项目需求,需要保存项目日志.项目的并发量不大,所以这里直接通过flume保存到oracle 源码地址:https://github.com/jaxlove/fks/tree/master/src/ ...
- Java lesson18homework
package com.xt.lesson19; import java.util.Scanner;import java.util.Set;import java.util.TreeSet; /** ...
- python中关于空的说法
0908自我总结 python中关于空的说法 python中表示空的数据 常量None 常量False 任何形式的数值类型零,如0,0L,0.0,0j 空的序列[],() 空的字典{} 用户自定义的n ...
- 学习笔记--三分法&秦九韶算法
前言 其实也没什么好说的吧,三分法就是用来求一个单调函数的最值和满足最大值的\(x\),秦九韶算法就是在\(O(N)\)时间内求一个多项式值 怎么用 三分法使用--看这篇:https://www.cn ...
- 【题解】JSOI2008 最大数
题目描述 现在请求你维护一个数列,要求提供以下两种操作: 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:L不超过当前数列的长度.(L>=0) 插 ...
- Laravel 表单验证创建“表单请求”实现自定义请求类
按照文档创建表单请求自定义类以后,调用总是403页面,咨询大佬说: public function authorize() { // 在表单验证类的这个方法这里要返回true,默认返回false,这个 ...
- 12 Django之Cookie和Session
一.什么是Cookie Cookie的由来 大家都知道HTTP协议是无状态的. 无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系,它不会受前面的请求响应情况直接 ...
- left join 和 inner join 区别和优化
关联查询总结,left join 和 inner join 区别和优化 一直以来都没有细细的研究 left join 和 inner join,现在发觉要做优化还真的是要熟悉它们的区别才行. 原谅转载 ...
- Rsyslog服务器的安装与配置
一.Rsyslog服务器的安装与配置 1.清空iptabels, 关闭selinux避免安装过中报错 清空iptables iptables -F service iptables save 关闭se ...
- 【异常】Could not find artifact com.wm.****:
1 详细异常 [ERROR] Failed to execute goal on project spark-etl: Could not resolve dependencies for proje ...