摘要:
http://acm.hdu.edu.cn/showproblem.php?pid=2087View Code #include<iostream>using namespace std;int main(){ char a[1001],b[1001]; int i,j; while(cin>>a) { if(a[0]=='#') break; cin>>b; int L1=strlen(a); int L2=strlen(b); int sign=0 , flag=0; i=sign,j=0; while(i<L1) { if(a[i 阅读全文
posted @ 2011-05-16 21:04
聊聊IT那些事
阅读(513)
评论(0)
推荐(0)
摘要:
View Code /*Poj2406题解:if(len%(len-next[len])==0),则重复子串的长度为 len-next[len].证明如下,next[len]表示到len为止,满足既是前缀子串又是后缀子串的最长长度,如下图{a,c} = {b,d}若len%(len – next[len])==0,则说明{ a ,b} 的长度可以被{a, d} 的长度整除,同样可以被{b,c}的长度整除。而此时,由于{b,c}是{b,d}的前缀子串又是后缀子串且保持{a,b}的长度可以被{a,c}整除。这样,{a,c}就相当于原来的{a,d},而{b,c}就相当于原来的{b,d},通过这样的划 阅读全文
posted @ 2011-05-16 20:10
聊聊IT那些事
阅读(666)
评论(0)
推荐(0)
摘要:
http://poj.org/problem?id=2752View Code //寻找前子串与后子串相等的子串#include<iostream>using namespace std;char ch[400001];int next[400001];int ans[400001];void solve (char *s, int ls){ int i=0,j=-1; next[0] = -1; while(i<ls) { if(j==-1 || s[i]==s[j]) { i++; j++; next[i] = j; } else { j = next[j]; } }}i 阅读全文
posted @ 2011-05-16 20:08
聊聊IT那些事
阅读(215)
评论(0)
推荐(0)

浙公网安备 33010602011771号