POJ3461 Oulipo ——KMP算法——Pku3461
生活随笔
收集整理的這篇文章主要介紹了
POJ3461 Oulipo ——KMP算法——Pku3461
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
建議大家學(xué)一學(xué)比較巧妙的KMP算法吧,很有意思。推薦個(gè)題目:POJ3167 Cow Patterns 題解我會(huì)發(fā)在本博里。
這個(gè)KMP就木有什么好說的了吧,大家找百度百科學(xué)一下就可以了~
CODE
Program KMP;//By_Thispoet Const maxn=1000005; Varst,s :Ansistring;//st is long and s is shortpre :Array[-1..maxn]of Longint;i,k,p,q,ans,n :Longint;BEGINreadln(n);while n>0 do beginreadln(st);readln(s);pre[1]:=0;for i:=2 to length(st) do begink:=pre[i-1];while (k<>0)and(st[k+1]<>st[i]) do k:=pre[k];if st[k+1]<>st[i] then pre[i]:=0 else pre[i]:=k+1;end;p:=0;q:=0;ans:=0;while q<length(s) do begininc(q);while (p<>0)and(st[p+1]<>s[q]) do p:=pre[p];if st[p+1]=s[q] then inc(p);if p=length(st) then begininc(ans);p:=pre[p];end;end;writeln(ans);dec(n);end;END.轉(zhuǎn)載于:https://www.cnblogs.com/Thispoet/archive/2011/09/14/2175350.html
總結(jié)
以上是生活随笔為你收集整理的POJ3461 Oulipo ——KMP算法——Pku3461的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 鼠标里面失灵怎么修复 鼠标故障如何修复
- 下一篇: AIX系统CPU性能评估-1