日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

P4391 [BOI2009]Radio Transmission 无线传输

發(fā)布時(shí)間:2025/5/22 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 P4391 [BOI2009]Radio Transmission 无线传输 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

吶吶吶題面

這題可以說是kmp的簡化版,也就是說只用求一下next數(shù)組,答案輸出為n-next[n],那么為什么呢,其實(shí)這也很好想,next[i]存儲(chǔ)的是下標(biāo)為i的前綴與從頭開始最長的相同前綴的尾下標(biāo),故next[n]表示的也就是除去第一個(gè)循環(huán)節(jié)之外的其他長度

#include<set> #include<map> #include<list> #include<queue> #include<stack> #include<string> #include<cmath> #include<ctime> #include<vector> #include<bitset> #include<memory> #include<utility> #include<cstdio> #include<sstream> #include<iostream> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; const int N=1000005;int n; char s[N]; int next[N];void getnext(){for(int i=2,j=0;i<=n;i++){while(s[i]!=s[j+1]&&j){j=next[j];}if(s[i]==s[j+1]){j++;}next[i]=j;} }int main(){scanf("%d",&n);cin>>(s+1);getnext();printf("%d\n",n-next[n]);return 0; }

  我還是得抽時(shí)間整理一下kmp完整版和簡化版的區(qū)別,有點(diǎn)略混。。

轉(zhuǎn)載于:https://www.cnblogs.com/hahaha2124652975/p/11146673.html

總結(jié)

以上是生活随笔為你收集整理的P4391 [BOI2009]Radio Transmission 无线传输的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。