
-字符串
文章平均质量分 81
virgoDd
Good afternoon,good evening and good night
展开
-
POJ 3080 Blue Jeans(KMP 最长公共子串)
Blue JeansDescriptionThe Genographic Project is a research partnership between IBM and The National Geographic Society that is analyzing DNA from hundreds of thousands of contributors to map how原创 2014-09-02 09:50:59 · 729 阅读 · 0 评论 -
UVa 1593 Alignment of Code(字符串)
题意 按要求对齐代码字符串流的应用#include using namespace std;const int N = 1005, M = 200;string s[N][M], line;int cw[M], cn[N];int main(){ int r = 0, c = 0; while(getline(cin, line)) {原创 2015-01-21 12:49:29 · 2249 阅读 · 0 评论 -
UVa 10391 Compound Words(复合词)
题意 输出所有输入单词中可以由另两个单词的组成的词STL set的应用 枚举每个单词的所有可能拆分情况 看拆开的两个单词是否都存在 都存在的就可以输出了#include using namespace std;string a, b;set s;set::iterator i;int main(){ int l; while(cin >> a) s.i原创 2015-01-21 17:49:37 · 1132 阅读 · 0 评论 -
Codeforces 527B Error Correct System(字符串)
题意 两个长度为n的只由小写字母组成的字符串a.b 问能否同时交换两个串两个对应位置的字符 使得两个串相同位置字符不相同的数目最小因为只能交换一次 所以只可能减少0,1或2个原创 2015-03-18 19:49:15 · 992 阅读 · 0 评论 -
POJ 3461 Oulipo (KMP字符串匹配·统计p在s中出现次数)
题意 给你两个字符串p和s 求p在s中出现的次数 很裸的kmp因为不止匹配一次 每次找到后还要循环j=next[j]的过程 知道到达s的终点#include#includeusing namespace std;const int N = 10005, M = 1000005;int next[N], ans, n;char p[N], s[M];void k原创 2014-09-02 09:51:32 · 1085 阅读 · 0 评论 -
HDU 1671 Phone List (Trie·数组实现)
题意 给你一组电话号码 判断其中是否有某个电话是另一个电话的前缀字典树的基础应用 可以先把所有电话存进Trie 标记每个电话的结束字符 然后再查询每个号码 看中途是否有结束标记 有的话就说明有号码是这个号码的前缀了实际上 插入完成就能知道是否有号码是另一个号码的前缀了 假设A是B的前缀若A在B之前插入 那么插入B的时候会遇到A的结束标记弱A在B之后插入 那么A原创 2015-07-27 19:56:43 · 891 阅读 · 0 评论 -
HDU 2846 Repository (Trie·统计子串)
题意 给你p个商品名称 然后输入q个字符串查询 对每个查询输出含有查询串为子串的商品个数Trie能很快的求出字典中以某个串为前缀的串的个数 但现在要查的是以某个串为子串的串的个数 可以发现 一个串的任何子串肯定是这个串某个后缀的前缀 如"ri"是“Trie" 的子串 是后缀 "rie" 的前缀 那么我们在向Trie中插入时可以把这个串的所有后缀都插入 插入时要注意原创 2015-07-28 09:06:04 · 1223 阅读 · 0 评论 -
HDU 1247 Hat’s Words (Trie·指针实现)
题意 给你一个字典 输出字典中能表示成两个单词连接的所有单词最基础的字典树应用 先把所有单词加入字典树中 标记每个结点是否为某个单词的结尾 然后查找每个单词 在树上查询过程中遇到单词结尾时 如果剩下的后缀也是一个单词 那当前查询的单词就可以是两个单词的连接了#include #include using namespace std;const int N = 5000原创 2015-07-27 16:43:11 · 867 阅读 · 0 评论 -
HDU 2328 Corporate Identity(Trie·最长公共子串)
题意 输出n个串的字典序最小的最长公共子串可以枚举第一个串的所有子串 然后对每个串kmp匹配 比较复杂 而且慢 发现和HDU2846(求模式串在n个串中出现的次数)有类似之处 都可以用Trie来处理 一个串的子串肯定是其某个后缀的前缀 我们把第一个串的所有后缀都插入到Trie中 最长公共子串肯定是在这个Trie里面的 因为它肯定是第一个串的子串 在插入后面的串的后缀时原创 2015-10-05 16:03:25 · 823 阅读 · 0 评论 -
UVa 12504 Updating a Dictionary(更新字典)
题意 比较两个字典 按字典序输出所有添加 删除 修改的项 如果没有任何更新 输出 No changesSTL map的应用 对比两个字典 注意开始字符串的处理和字典可以为空#includeusing namespace std;map d[2];map::iterator it;const int N = 105;string s, a, b, t[N];vo原创 2015-01-22 16:16:49 · 2162 阅读 · 0 评论 -
CF 505A Mr. Kitayuta's Gift(暴力)
题意 在一个字符串中插入一个字母使其变成一个回文串 可以的话输出这个回文串 否则NA大水题 插入情况最多就26*11种 可以直接暴力#include#includeusing namespace std;const int N = 20;char s[N], p[N];int l;bool ispal(){ for(int i = 0; i < (l + 1原创 2015-01-19 09:00:59 · 1766 阅读 · 0 评论 -
UVa 340 Master-Mind Hints
Master-Mind Hints MasterMind is a game for two players. One of them, Designer, selects a secret code. The other,Breaker, tries to break it. A code is no more than a row of colored dots.原创 2014-09-02 09:50:15 · 548 阅读 · 0 评论 -
POJ 2250 Compromise (DP,最长公共子序列)
CompromiseTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 6440Accepted: 2882Special JudgeDescriptionIn a few months the European Currency Union原创 2014-09-02 09:50:38 · 587 阅读 · 0 评论 -
UVa 1339 Ancient Cipher
Ancient CipherAncient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capit原创 2014-09-02 09:50:13 · 602 阅读 · 0 评论 -
UVa 489 Hangman Judge(字符串)
Hangman Judge In ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are t原创 2014-09-02 09:50:11 · 603 阅读 · 0 评论 -
UVa 213 Message Decoding(World Finals1991,字符串)
Message Decoding Some message encoding schemes require that an encoded message be sent in two parts. The first part, called the header, contains the characters of the message. The second原创 2014-09-02 09:50:17 · 880 阅读 · 0 评论 -
UVa 401 Palindromes(镜像回文字符串)
题意 给一个字符串 判定其是否为回文串和镜像串 回文串很好判断 镜像串对于每一个字符用数组保存它的镜像字符就行了 没有的就是空格注意若字符串长度为奇数 中间那个字母必须是对称的才是镜像串#include#include#includeconst int N = 35;int l;char s[N], mc[] = "A 3 HIL JM O原创 2014-08-30 09:28:54 · 1500 阅读 · 0 评论 -
UVa 1584 Circular Sequence(环形串最小字典序)
题意 给你一个环形串 输出它以某一位为起点顺时针得到串的最小字典序直接模拟 每次后移一位比较字典序即可 注意不能用strcpy(s+1,s)这样后移 strcpy复制地址不能有重叠部分#include #include using namespace std; const int N = 150; char s[N], ans[N],原创 2014-08-31 09:09:36 · 1313 阅读 · 0 评论 -
hihoCoder 1014 Trie树(基础字典树)
题意 中文最基础的字典树应用噢噢噢噢#include#includeusing namespace std;struct trie{ trie *chi[26]; int num; trie() { num = 0; for(int i = 0; i < 26; ++i) chi[i] = N原创 2014-12-11 16:40:28 · 1437 阅读 · 0 评论 -
HDU 3374 String Problem(最小表示法·KMP)
题意 给你一个环形串 输出其最小表示法的首字母位置 最大表示法的首字母位置 以及和对应位置等价位置的个数最小表示法指一个循环串以某一位开始时对应的串的字典序最小 这个串就是该循环串的最小表示法 先看一下求字符串最小表示法的过程 可以看2003年国家集训队论文集中周源的论文令 p 表示字符串 s 的最小表示法的下标, l = strlen(s) s = s + s原创 2015-10-06 10:43:25 · 1237 阅读 · 0 评论