2012年7月20日

Saving Princess claire 最短路

摘要: 比赛中非常水的一道题,结束时大家才做。。没提交上。。泪奔。。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<iostream>#include<algorithm>#include<map>#include<math.h>#include<queue>using namespace std;int N,M,C,n, maxn;int xx[]={1,0,0,-1};int yy[]={0,1,-1,0}; 阅读全文

posted @ 2012-07-20 22:25 more think, more gains 阅读(160) 评论(0) 推荐(0) 编辑

HDU 4300 Clairewd’s message

摘要: 这题比赛时,题意看了N久才看懂,囧。。。算法又错了两次:错误算法:1. 用二分找密文长度。。2.用只求了一次next函数找最长前缀匹配后缀,忽略了其可能有交集,在这题中是不允许的。。正确算法:饶了这么多弯,终于回到正道了,求一次KMP就可以解决。用截获的文本后半段做主串,用前半段做模式串。用KMP求出其最长匹配主串的长度。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>char str[101000];char st[101000];char temp1[101000];char 阅读全文

posted @ 2012-07-20 22:22 more think, more gains 阅读(179) 评论(0) 推荐(0) 编辑

KMP 算法

摘要: KMP算法核心 next函数:1.定义: next[k] =1) k = 1时,next[k] = 0;2) = max( k | { 1 < k < j ) { p[1...k-1] = p[j-k+1...j-1] }3) 其他情况 next[k] = 12.递推求解1) 定义,next[1] = 0, 假设next[j] = k, p[1..k-1] = p[j-k+1..j-1]2) 若p[j] = p[k], p[1..k] = p[j-k+1..j], next[j+1] = next[j] + 1 = k + 1;3) 若p[j] != p[k],匹配失败时 k = 阅读全文

posted @ 2012-07-20 15:05 more think, more gains 阅读(205) 评论(0) 推荐(0) 编辑

导航