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树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已 ...
随机推荐
- ssh无密登录_集群分发脚本xsync
1.ssh免密登录 ssh ip地址 [root@192 ~]# ssh 192.168.1.102 root@192.168.1.102's password: Last login: Mon Fe ...
- date和time
time和date两个函数在Lua中实现所有的时钟查询功能.函数time在没有参数时返回当前时钟的数值. t=os.date()print(t) 05/07/19 16:49:18 --------- ...
- golang(8):channel读写 & goroutine 通信
goroutine 1.进程和线程 A. 进程是程序在操作系统中的一次执行过程,系统进行资源分配和调度的一个独立单位 B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独 ...
- 爬虫中什么是requests
print(response.text) #响应的信息 print(response.headers) #获取响应头 print(response.status_code) #响应状态码 print( ...
- ython实现进程间的通信有Queue,Pipe,Value+Array等,其中Queue实现多个进程间的通信,而Pipe实现两个进程间通信,而Value+Array使用得是共享内存映射文件的方式,所以速度比较快
1.Queue的使用 from multiprocessing import Queue,Process import os,time,random #添加数据函数 def proc_write(qu ...
- Hadoop 3相对于hadoop 2的新特性
相对于之前主要生产发布版本Hadoop 2,Apache Hadoop 3整合许多重要的增强功能. Hadoop 3是一个可用版本,提供了稳定性和高质量的API,可以用于实际的产品开发.下面简要介绍一 ...
- video 轮播视频
<video controls :src="product.videoUrl" :poster="resURL + defaultImg">< ...
- js小功能2:切换
HTML: <div id="tb"> <ul><li class="on">房产</li><li> ...
- php 随笔 截取字符串 跳出循环 去除空格 修改上传文件大小限制
substr(string,start,length) echo substr("Hello world",6); world 跳出循环 for($i=1; $i<5; $i ...
- 目标检测之车辆行人(darknet版yolov3)
序言 自动驾驶是目前非常有前景的行业,而视觉感知作为自动驾驶中的“眼睛”,有着非常重要的地位和作用.为了能有效地识别到行驶在路上的动态目标,如汽车.行人等,我们需要提前对这些目标的进行训练, ...