==== 字符串 ====
柠檬不酸只是萌
遇 见 最 美 的 自 己 。
展开
-
HDU 1020 — Encoding
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1020题意:计算字符串中各字母的个数,1不必标记;#include#includechar s[10005];int main(){ int cas; scanf("%d", &cas); while(cas--) { scanf("%s", s); int len原创 2015-04-27 21:06:04 · 522 阅读 · 0 评论 -
KMP讲解
【KMP算法简介】 KMP算法是一种改进后的字符串匹配算法,由D.E.Knuth与V.R.Pratt和J.H.Morris同时发现,因此人们称它为克努特——莫里斯——普拉特操作(简称KMP算法)。通过一个辅助函数实现跳过扫描不必要的目标串字符,以达到优化效果。 【传统字符串匹配算法的缺憾】 Bi转载 2015-08-17 15:43:40 · 443 阅读 · 0 评论 -
HDU 1867 — A + B for you again
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1867题意:给你两个字符串T和P,将他们相连(T在P前面,P在T前面均可),首先要求尽可能多的覆盖住重复部分,其次满足按字典序输出;思路:用KMP分别求出两种情况下的匹配数,选取匹配数多的那一种;当两者的匹配数相等时,选取字典序小的字符串在前面;#include#i原创 2015-08-17 21:40:26 · 477 阅读 · 0 评论 -
HDU 2203 — 亲和串
原题:http://acm.hdu.edu.cn/showproblem.php?pid=2203思路:将T串扩增成TT串,就相当于循环移位了一周;#include#includeconst int maxn = 100005;char T[maxn*2], P[maxn];int f[maxn], n, m;bool find(){ int原创 2015-08-17 15:39:11 · 592 阅读 · 0 评论 -
HDU 1711 — Number Sequence简单题
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1711题意:给出两个数字串,问b串在a串中第一次出现的位置;KMP模板题#include#includeconst int maxn = 1e6+5;int a[maxn], b[maxn], f[maxn];int n, m;void getFail()原创 2015-08-17 14:40:16 · 440 阅读 · 0 评论 -
HDU 1671 — Phone List
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1671题意:给出一些号码,如果其中一个号码是另一个的前缀,则输出NO;思路:插入每个号码时,内部数字val = 0,最后一个数字val = 1;#include#include#define MAX 26const int maxnode = 4000*100原创 2015-08-16 10:31:51 · 411 阅读 · 0 评论 -
HDU 1251 — 统计难题
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1251题意:给出一些单词;下面给出一些字符串,计算以该字符串为前缀的单词个数;思路:字典树模板题,只要在插入单词的时候每个字母所路过的节点的val都+1;#include#include#define MAX 26const int maxnode=4000*原创 2015-08-15 19:45:13 · 403 阅读 · 0 评论 -
HDU 2222 — Keywords Search
原题:http://acm.hdu.edu.cn/showproblem.php?pid=2222题意:给出n个模板以及文本,问文本中出现了多少个模板;思路:要注意有重复的模板,也是要算数的;用val数组来计算每种模板的个数;用vis数组来表示单词的节点;#include#include#include#includeusing names原创 2015-08-25 20:53:42 · 429 阅读 · 0 评论 -
HDU 1113 — Word Amalgamation
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1113题意:给出一部字典,然后输入一些字符串,从字典中查找是否有相对应地单词,若没有则输出NOT A VALID WORD;#include#include#include#include#includeusing namespace std;string str;map原创 2015-07-12 11:33:18 · 430 阅读 · 0 评论 -
HDU 1004 — Let the Balloon Rise
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1004题意:给定n个颜色,求个数最多的颜色;思路:col[i]保存不同的颜色;num[i]记录各种颜色的个数;每次输入一个颜色就和所有col数组进行比较,若col中有该种颜色,就将对应的num+1;若没有,则将该种颜色放到col数组中去;#includ原创 2015-07-03 11:37:25 · 404 阅读 · 0 评论 -
HDU 1088 — Write a simple HTML Browser
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1088题意:1、遇到换行;2、遇到输出“--------------------------------------------------------------------------------”3、每行长度不得超过80,单词间有空格;#include#inc原创 2015-07-12 10:29:56 · 465 阅读 · 0 评论 -
HDU 1062 — Text Reverse
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1062 #include#includechar s[1100];char a[1100];int main(){ int cas; scanf("%d", &cas); getchar(); while(cas--) { gets(s); int len = strl原创 2015-04-27 22:20:00 · 322 阅读 · 0 评论 -
HDU 1039 — Easier Done Than Said?
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1039题意: 需满足以下三种情况: 1、至少存在一个元音字母; 2、不能连续三个都为元音或者都为辅音; 3、相邻两个字母不能相同,除了‘ee’和‘oo’;原创 2015-04-27 21:57:59 · 446 阅读 · 0 评论 -
HDU 2594 — Simpsons’ Hidden Talents
原题:http://acm.hdu.edu.cn/showproblem.php?pid=2594题意:给出两个字符串S1, S2,找出S1中最长的可以和S2的后缀匹配的前缀;思路:将S1作为模式串,S2作为目标串,用KMP就好,看到S2的最后一个字符时能匹配S1中的第几个字符;#include #include const int max原创 2015-08-19 16:29:20 · 496 阅读 · 0 评论