poj 3158 Kickdown 字符串匹配?
2015-02-01 11:00
190 查看
也是uva 1588
这种题目不禁让人想到KMP
可是这个长度才100啊想怎么暴力就怎么暴力 用的就是传说中的BF算法(brute-force)
把短串加到长串的两边 然后匹
swap和strncpy用的飞起不枉我重修了一遍计导和c语言
poj题目链接:http://poj.org/problem?id=3158
这种题目不禁让人想到KMP
可是这个长度才100啊想怎么暴力就怎么暴力 用的就是传说中的BF算法(brute-force)
把短串加到长串的两边 然后匹
swap和strncpy用的飞起不枉我重修了一遍计导和c语言
poj题目链接:http://poj.org/problem?id=3158
#include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <cmath> #include <set> #include <queue> #include <stack> #include <map> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; const int maxn = 310; int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); char a[maxn], b[maxn], c[maxn]; while(scanf("%s%s", a, b) == 2) { int alen = strlen(a); int blen = strlen(b); if(alen < blen) { swap(a, b); swap(alen, blen); } int clen = 2*blen + alen; fill(c, c + blen, '1'); strncpy(c+blen, a, alen); fill(c + blen + alen,c + 2*blen + alen, '1'); int ans = alen + blen; for(int j = 0; j < clen-blen; j++) { bool flag = true; int tmp; for(int i = 0; i < blen && flag; i++) { if(c[j+i] - '0' + b[i] - '0' > 3) flag = false; } if(flag) { if(blen <= j && j <= alen) { ans = alen; break; } else if(j < blen) { tmp = alen + blen - j; if(tmp < ans) ans = tmp; } else if(j > alen) { tmp = j; if(tmp < ans) ans = tmp; } } } printf("%d\n", ans); } return 0; }
相关文章推荐
- poj 1226 暴力字符串匹配
- poj 3461 Oulipo 字符串匹配 KMP算法
- KMP 字符串匹配 POJ 3461 Oulipo
- poj-3461 kmp字符串匹配问题
- POJ 3158 Kickdown(我的水题之路——齿轮盒子,读题失败)
- poj 3158kickdown
- POJ 1936(字符串匹配)
- POJ 3461 Oulipo(字符串匹配,KMP算法)
- poj 1936 All in All 简单的字符串匹配
- HDU 1606(POJ 1598 UVA 409) Excuses, Excuses!(字符串匹配处理)
- POJ 3267 The Cow Lexicon DP 字符串匹配 一主串n个子串最少在主串删除多少字母,可以匹配到n 个单词序列中的一些完整单词
- POJ 3158 Kickdown
- POJ 3080 (字符串匹配)
- 字符串匹配之KMP算法(POJ 3461 Oulipo)
- POJ 3158 Kickdown(水~)
- POJ 3276 The Cow Lexicon DP-字符串匹配
- POJ 2403 字符串匹配 暴力过
- POJ-1266/KMP算法/字符串匹配
- POJ - 3267 The Cow Lexicon 字符串匹配 (dp)
- HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)