
字符串
xjsong99
OI -> ACM -> AI
展开
-
string char* char[]的转换
(转载) 1、首先必须了解,string可以被看成是以字符为元素的一种容器。字符构成序列(字符串)。有时候在字符序列中进行遍历,标准的string类提供了STL容器接口。具有一些成员函数比如begin()、end(),迭代器可以根据他们进行定位。注意,与char*不同的是,string不一定以NULL(‘\0’)结束。string长度可以根据length()得到,string可以根据下标访问。所以转载 2015-06-13 21:43:33 · 330 阅读 · 0 评论 -
HDU 3247. Resource Archiver (AC自动机+bfs+DP)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=3247题意:给定n个串,将他们放在一个串s中,可以重叠;给定m个串,要求s中不能出现这m个串;问s最小多长。分析:两篇很好的题解:https://blog.youkuaiyun.com/woshi250hua/article/details/8021283https://www.cnblogs.com...原创 2019-08-15 11:05:19 · 551 阅读 · 0 评论 -
POJ 1451. T9 (Trie+map)
题目: http://poj.org/problem?id=1451题意:给定一个数据库,包含每个字符串出现的次数;对于每一个询问,给定一个数字串(9键拼音),输出键入每个数字时出现概率最大的字符串。分析:Trie树+map即可实现。代码:#include <iostream>#include <cstdio>#include <map>#i...原创 2019-08-07 10:44:00 · 455 阅读 · 0 评论 -
HDU 3336. Count the string (KMP-next数组)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=3336题意:给定一个串s;求各个前缀的出现次数之和。分析:用KMP求得next数组之后,将next数组中递增的一串数的最后一个加到答案中即可;别忘了每个前缀自己也算出现了一次。代码:#include <bits/stdc++.h>using namespace std;ty...原创 2019-08-06 18:49:30 · 360 阅读 · 0 评论 -
HDU 2457. DNA repair (AC自动机+DP)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2457题意:给n个患病DNA串;给1个DNA串,问最少修改几个(只能用字符AGCT)能使得所有患病DNA串未出现过。分析:AC自动机上做动态规划。就像在Trie上走,去构造一个串;设f[i][j]表示长度为i,Trie树上节点为j时最少替换的字符数;则答案为min(f[len][j]), ...原创 2019-08-13 15:24:28 · 382 阅读 · 0 评论 -
HDU 3613. Best Reward (扩展KMP/Manacher)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=3613题意:给定一个字符串s;每个字符有一个权值;砍成两段,若某段为回文串则其价值为各字符的价值和,非回文串则价值为0;问两段的价值和最大是多少。分析:法一:做完Manacher,枚举砍点就是了。法二:设给定字符串为s,将其反转后为t;以s为文本串,t为模板串跑exKMP,得到ext...原创 2019-08-06 15:12:17 · 386 阅读 · 0 评论 -
HDU 6625. three arrays (Trie×2)
题目: http://acm.hdu.edu.cn/showproblem.php?pid=6625题意:给定两个长为n的数组a和b;重新排列a和b,生成数组c,c[i]=a[i] xor b[i];输出字典序最小的c数组。分析:将a中的数插入一颗01字典树a中;将b中的数插入一颗01字典树b中;在trie树上查找n次,每次同时在a和b中下移一层;if 能同时走0,则同时走0;...原创 2019-08-08 15:44:06 · 446 阅读 · 0 评论 -
HDU3068 最长回文 (Manacher)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3068分析: Manacher模板题代码:#include <bits/stdc++.h>using namespace std;typedef long long ll;const int tmax=1100005;int len,id,p[tmax*2];char...原创 2018-08-10 20:31:07 · 146 阅读 · 0 评论 -
HDU6299 Balanced Sequence(2018多校第一场1002) (贪心)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6299题意: 给n个字符串,对其重排序,求排序后最大匹配的左右括号数分析: 1.首先,单个字符串自身内部匹配的括号不予考虑,因为无论怎么排序他们仍然匹配; 2.对于多个字符串,自身内部匹配后 [剩余’(‘多的串] 应排在 [剩余’)’多的串] 前面; 3.而对于放在前面的串,为了使他们能匹配...原创 2018-08-06 10:14:28 · 136 阅读 · 0 评论 -
UVA11019 Matrix Matcher (二维AC自动机)
题目:https://vjudge.net/problem/UVA-11019题意: 给一个 n*m大矩阵,一个 x*y小矩阵; 求小矩阵在大矩阵中出现次数。分析: 将小矩阵按行插入Trie树中; 结尾标记val为行号; 注意有可能多行对应一个节点,因此val应为vector; find()大矩阵中每行,若出现匹配,则标记这次匹配对应的小矩阵右上角出现的位置; 若一个位置被标...原创 2018-08-10 10:36:42 · 247 阅读 · 0 评论 -
HDU2222 Keywords Search (AC自动机)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2222分析: AC自动机模板题代码:#include <bits/stdc++.h>using namespace std;typedef long long ll;const int tmax=10005*30;const int tmax2=1e6+5;int n...原创 2018-08-09 20:07:15 · 128 阅读 · 0 评论 -
牛客 - Psd面试
题目:https://www.nowcoder.com/acm/contest/90/D题意: 求最长回文子序列(注意不是子串)分析: 法一:直接O(n^2) DP f[i][j] = max( f[i+1][j] , f[i][j-1] , f[i+1][j-1]+2 ) , s[i]==s[j] = max( f[i+1][j] , f[i][j-1] ) ...原创 2018-03-26 21:23:56 · 173 阅读 · 0 评论 -
HDU5972 Regular Number (ShiftAnd算法+bitset)
题意: 在一个合法串中:每位上有多个可选字符(数字),求母串中有多少个这样的合法子串。 注意:用gets和puts,并且选择G++而不是C++!(否则TLE) 分析: 一开始写了KMP算法,结果发现没有可重复性,退化为O(n^2),TLE; 正解为ShiftAnd算法,用bitset实现; 1.bitset B[i][j]==1表示数i可以在第j位出现; 2.维护一个bitset an原创 2017-10-01 20:39:24 · 394 阅读 · 0 评论 -
17ACM Qingdao 1010 Brute Force Sorting
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6215 分析:利用类似并查集的方法,记录消除完毕后当前元素的左右元素。 代码:#include <cstdio>#include <algorithm>#include <cstring>#include <queue>using namespace std;const int Tmax=100原创 2017-09-20 23:52:22 · 184 阅读 · 0 评论 -
NOI库6252 带通配符的字符串匹配
题目:http://noi.openjudge.cn/ch0206/6252/ 分析:注意b是空串!!j从0开始! 代码:#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int Tmax=105;char a[Tmax],b[Tmax];int la,lb;bool f原创 2015-10-20 21:03:04 · 806 阅读 · 0 评论 -
CF#306(Div. 2) E-Brackets in Implications
题目:http://codeforces.com/contest/550/problem/E 分析:尝试最后两位: 0 1 一定是1 1 0 一定是0 1 1 一定是1 0 0 比较复杂,可以分成:…->(0->(…->0))->0 代码:#include <cstdio>#include原创 2015-06-13 21:59:35 · 401 阅读 · 0 评论 -
BZOJ 3261. 最大异或和 (可持久化Trie)
题目: https://www.lydsy.com/JudgeOnline/problem.php?id=3261题意:给定n个数,q个操作;操作有两种类型;第一种:在n个数后添加一个数;第二种:给定L、R、X,求a[p] xor a[p+1] xor ... xor a[N] xor x,其中p∈[L,R]分析:可持久化Trie裸题代码:原创 2019-08-12 20:03:08 · 421 阅读 · 0 评论