题目链接: D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q que…
D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries a…
题目链接:http://codeforces.com/contest/706/problem/D 题意很简单不多说. 把一个数当作二进制插入字典树中,按照xor的性质,1找0,0找1,贪心即可. 注意的是一开始集合中就有0,所以一开始'?'查询时输出他本身. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #incl…
题目链接: http://codeforces.com/contest/706/problem/D D. Vasiliy's Multiset time limit per test:4 secondsmemory limit per test:256 megabytes 问题描述 Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q…
D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries a…
题目大概说给两个串,问最少要用多少个第一个串的子串(可以翻转)拼成第二个串. UVa1401,一个道理..dp[i]表示前缀i拼接成功所需最少的子串,利用第一个串所有子串建立的Trie树往前枚举转移. #include<cstdio> #include<cstdlib> using namespace std; #define MAXN 2222*2000 ],from[MAXN],to[MAXN]; ],S[]; ],rec[]; void pnt(int x){ ) retur…
<题目链接> 题目大意:给定一个只有小写字母组成的目标串和m个模式串(里面可能有大写字母),记目标串反过来后的串为S,让你从m个模式串中选出若干个组成S串(不区分大小写).输出任意一种方案. 解题分析:将所有单词倒着建好Trie树后(字母忽略大小写),直接在Trie树上跑DFS,记录下所有符合条件的单词序号,然后输出即可. #include <cstdio> #include <cstring> #include <algorithm> using name…
<题目链接> 题目大意:输入n个单词构成单词库,然后进行m次查询,每次查询输入一个单词(注意这些单词只由a,b,c构成),问该单词库中是否存在与当前查询的单词有且仅有一个字符不同的单词. 解题分析:本题将单词库中所有的单词先建trie树,然后进行容错数为1的字符串匹配,主要是在trie树上跑DFS,具体步骤见代码: #include <cstdio> #include <cstring> #include <algorithm> using namespac…
题意:最开始的时候有一个集合,集合里面只有一个元素0,现在有q次操作,操作分为3种: + x: 表示向集合中添加一个元素x - x:表示删除集合中值为x的一个元素 ? x:表示查询集合中与x异或的最大值为多少 析:这是一个字典树的应用,不过确实没看出来....主要思想是这样,先用10进制数,转成二进制数,记下每个结点的0,1的个数,这样增加和删除,就是对01的删除, 剩下的就是查询,那么尽量让0和1XOR是最大的,所以,对于给定数,我们要去尽量他的XOR数,如果找到就加上,找不到,就找下一个.这…
time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries and a multiset A, initi…
题目大意:需要维护一种数据结构,支持以下三种操作:插入一个数,删除一个数,查询该数据结构中的数异或给定数的最大值. 题解:如果没有删除操作就是一个标准的 Trie 上贪心求最大异或和问题.现在需要支持删除操作,因此,在树上每个节点维护一个额外的标记,表示有多少个数的某一位经过当前节点.插入操作依然只需修改树上一条链,而删除一个数时,同样需要将这条链上的标记值减 1 即可.这时便可以根据经过的每个点标记值是否为 0 进行贪心操作. 代码如下 #include <bits/stdc++.h> us…
字典树 简介:字典树,又称单词查找树,Trie树,是一种树形结构,是哈希树的变种. 优点:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较. 性质:根节点不包含字符,除根节点外每一个节点都只包含一个字符: 从根节点到某一节点,路径上经过的字符连接起来,为该节点对应的字符串: 每个节点的所有子节点包含的字符都不相同. 操作: 记trie[i][j]表示第i个节点的第j个儿子为哪个节点,tot为总的节点个数 插入: void insert() { int len = strlen(…
// trie树 Codeforces Round #367 D Vasiliy's Multiset // 题意:给一个集合,初始有0,+表示添加元素,-去除元素,?询问集合里面与x异或最大的值 // 思路:思路很好想,建立trie树,再贪心当前位是1则选0,0则选1 #include <bits/stdc++.h> using namespace std; #define LL long long const double inf = 123456789012345.0; const LL…
D. Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries a…
Vasiliy's Multiset 题目链接: http://codeforces.com/contest/706/problem/D Description Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries and a multiset A, initially containing only integer…
题目链接:Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset 题意: 给你一些操作,往一个集合插入和删除一些数,然后?x让你找出与x异或后的最大值 题解: trie树xjb搞就行,每次要贪心,尽量满足高位为1. #include<bits/stdc++.h> #define F(i,a,b) for(int i=a;i<=b;i++) using namespace std; namespace trie { )*; ],ed=-,c…
Codeforces 633C Spy Syndrome 2 | Trie树裸题 一个由许多空格隔开的单词组成的字符串,进行了以下操作:把所有字符变成小写,把每个单词颠倒过来,然后去掉单词间的空格.已知操作后的字符串以及可能出现的所有单词,请输出原字符串(多组解只输出一个). 我犯的错误:数组的trie树--如果根节点是1--则其余节点要从2开始啊啊啊 #include <cstdio> #include <cstring> #include <algorithm> u…
题目链接 大意是判断所给字符串组中是否存在与查询串仅一字符之差的字符串. 关于字符串查询的题,可以用字典树(Trie树)来解,第一次接触,做个小记.在查询时按题目要求进行查询. 代码: #define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<…
D. Acyclic Organic Compounds   You are given a tree T with n vertices (numbered 1 through n) and a letter in each vertex. The tree is rooted at vertex 1. Let's look at the subtree Tv of some vertex v. It is possible to read a string along each simple…
<题目链接> 题目大意: 现在给定出n个字符串,并且进行m此询问,每次询问给出一个匹配串,每次询问都给出该匹配串能够匹配的字符串个数(题目只出现字符'a'~'e').'?'可以看成任意字符,也可以看做没有. 解题分析: 对这n个字符串建立Trie树,然后对每次输入的匹配串在trie树上进行模糊匹配,'?'的分类匹配主要体现在Trie树上的DFS过程. #include<bits/stdc++.h> using namespace std; ; ; ], val[N*M], flag…
<题目链接> 题目大意: 输入7e4个长度为9的字符串,每个字符串中只出现0~9这几种数字,现在需要你输出每个母串中最短的特有子串. 解题分析: 利用Trie树进行公共子串的判定,因为Trie树的特性是对节点的前缀字符串进行操作,所以为了转换成对母串中任意区间的字符串进行操作,我们对母串中的所有后缀字符串建树.下面用了一个比较优秀的Trie树模板. #include <cstdio> #include <cstring> #include <iostream>…
Peterson loves to learn new languages, but his favorite hobby is making new ones. Language is a set of words, and word is a sequence of lowercase Latin letters. Peterson makes new language every morning. It is difficult task to store the whole langua…
题目链接: E. Beautiful Subarrays time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output One day, ZS the Coder wrote down an array of integers a with elements a1,  a2,  ...,  an. A subarray of the arr…
Vasiliy's Multiset time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given q queries and…
题意:有一棵n个结点的只由小写字母组成的Trie树,给定它的具体形态,问删除哪一层后剩下Trie树的结点数最少 n<=3e5 思路:先建出原Trie树,对于每一层的每一个结点计算删除后对答案的贡献,这一部分使用启发式合并 官方题解证明了时间复杂度是一个log的 http://codeforces.com/blog/entry/50724 #include<cstdio> #include<cstring> #include<iostream> #include&l…
前言:本文章来源于我在知乎上回答的一个问题 AVL树,红黑树,B树,B+树,Trie树都分别应用在哪些现实场景中? 看完后您可能会了解到这些数据结构大致的原理及为什么用在这些场景,文章并不涉及具体操作(如插入删除等等) 文件夹 AVL树 AVL树原理与应用 红黑树 红黑树原理与应用 B/B+树 B/B+树原理与应用 Trie树 Trie树原理与应用 AVL树 简单介绍: AVL树是最早的自平衡二叉树,在早期应用还相对来说比較广.后期因为旋转次数过多而被红黑树等结构代替(二者都是用来搜索的).AV…
[题解]HDU5845 Best Division (trie树) 题意:给定你一个序列(三个参数来根),然后请你划分子段.在每段子段长度小于等于\(L\)且子段的异或和\(\le x\)的情况下最大化分出子段的个数 区间/子段/序列这种东西一大性质就是右端点之后与前面无关. \(dp(i)\)表示上一个右端点是\(i\)且前面分出来的子段都满足条件的最多子段个数. 直接转移\(O(n^2)\)考虑优化这个东西,子段转前缀和是应该记起来的套路,现在问题就是变成查询两个前缀和的异或值是否满足条件.…
链接:https://codeforces.com/problemset/problem/1285/D 题意:给n个数a1,a2,a3.....an,找到一个数X,使得X 异或所有的ai ,得到的max(X xor ai)最小,输出这个值. 思路:a的范围是0~230,我们可以以01二进制的形式建一棵深度为30的字典树,每个数ai 的二进制序列插入到字典树中去,例如5 = 101,那么101按位插入到字典树中去.然后从根开始遍历,在字典树上dp,因为该字典树建完后是一棵二叉树,所以分支情况就两种…
基于trie树做一个ac自动机 #!/usr/bin/python # -*- coding: utf-8 -*- class Node: def __init__(self): self.value = None self.children = {} # children is of type {char, Node} self.fre = 0 self.father = None self.fail = None def CMP(a, b): return b.fre - a.fre cla…
之前的软件设计与开发实践课程中,自己构思的大作业题目.做的具有核心功能,但是还欠缺边边角角的小功能和持久化数据结构,先放出来,有机会一点点改.github:https://github.com/chuxiuhong/smarteditor 数据结构,使用过程截图以及源代码如下: #数据结构 **trie树** trie树相应的介绍点击链接 https://en.wikipedia.org/wiki/Trie trie树在python文件中的类型定义 Node定义 #GUI设计界面 首先,用较大的…