日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【POJ - 2752】Seek the Name, Seek the Fame (KMP,公共前缀后缀长度及个数)

發布時間:2023/12/10 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【POJ - 2752】Seek the Name, Seek the Fame (KMP,公共前缀后缀长度及个数) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm:?

Step1. Connect the father's name and the mother's name, to a new string S.?
Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S).?

Example: Father='ala', Mother='la', we have S = 'ala'+'la' = 'alala'. Potential prefix-suffix strings of S are {'a', 'ala', 'alala'}. Given the string S, could you help the little cat to write a program to calculate the length of possible prefix-suffix strings of S? (He might thank you by giving your baby a name:)?

Input

The input contains a number of test cases. Each test case occupies a single line that contains the string S described above.?

Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.?

Output

For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby's name.

Sample Input

ababcababababcabab aaaaa

Sample Output

2 4 9 18 1 2 3 4 5

題目大意:

給一個字符串S,找一個 S 的“前綴-后綴串”作為新生兒的名字(“前綴-后綴串”的定義是 既是S的前綴,又是S的后綴)?

比如:S = 'alala'。S的 “前綴-后綴串” 是{'a','ala','alala'}。給定字符串S,讓你計算S的可能? “前綴-后綴串”? 的長度。

解題報告:

? 求到最后一個字符的next數組,然后每次跳轉到next,,最后倒序輸出 就可以得到答案了

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e6 + 5; char s[MAX]; int Next[MAX],len,ans[MAX]; void getnext() {Next[0] = -1;int k = -1,j = 0;int len = strlen(s);while(j < len) {if(k == -1 || s[k] == s[j]) {k++,j++;Next[j] = k;} else k = Next[k];} } int main() {int n;while(~scanf("%s",s)) {getnext();int j = strlen(s),tot = 0;while(j) ans[++tot] = j,j = Next[j];for(int i = tot; i>=1; i--) {printf("%d%c",ans[i], i == 1 ? '\n' : ' ');}}return 0; }

總結:

? 這也告訴我們next數組中只有next[0] 才= -1;其他的就算是沒有,也是=0;;;main函數中這個while(j)就可以證明這一點、、、

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的【POJ - 2752】Seek the Name, Seek the Fame (KMP,公共前缀后缀长度及个数)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲av无码不卡一区二区三区 | 91色在线观看 | 国产黄站| 美腿丝袜亚洲色图 | 午夜一二区 | 夜夜欢视频 | 欧美午夜在线 | 国产三级午夜理伦三级 | 亚洲在线观看视频 | 国产成人精品一区二区无码呦 | 91免费在线播放 | 国产一区二区视频播放 | 日本视频免费看 | 国产精品美乳在线观看 | 在线观看污 | 小明天天看 | 69视频在线播放 | 女生和男生一起插插插 | 黄色高清在线观看 | 中文字幕在线观看av | 你懂的网址在线 | a点w片 | 中文字幕乱码亚洲精品一区 | 国产成人av无码精品 | 麻豆国产一区二区三区 | 日韩一级高清 | 成人免费看片' | 日韩精品久久久久久久酒店 | 天天干网 | 五月天中文字幕av | 五月依人网 | 久久久777| 蜜桃精品久久久久久久免费影院 | 国产精品久久国产精品 | 日日夜夜操av | 天堂av最新网址 | 国产精品爽爽久久 | 欧美理论在线观看 | 午夜在线观看视频网站 | 欧美日韩999 | 亚洲国产日韩精品 | 亚洲av综合一区二区 | 人妖一区| 国内精品视频一区 | 亚洲国产视频在线观看 | 久久影院午夜理论片无码 | 精品国产乱码一区二区三区99 | 毛片精品| 午夜精品毛片 | 亚洲黄色一级大片 | 久久亚洲少妇 | 亚洲精品久久久久久久久久 | 91综合色 | 精品丝袜一区 | 欧美成人三级在线观看 | 少妇一级淫免费播放 | 香蕉视频一区二区 | 中文字幕在线精品 | 国产精品亚洲一区 | 能看的毛片 | 久久九九免费视频 | 最近最新最好看的2019 | 伊人99re | 38在线视频| 日韩电影在线一区二区 | 这里都是精品 | 国产三级久久 | 中文字幕av观看 | 中文字幕第一区综合 | 国产一区二区片 | 国产网红av| 久热免费在线 | 久久久久亚洲色欲AV无码网站 | 欧美亚洲自拍偷拍 | 亚洲女人久久久 | 超碰日日干| 日韩亚洲视频在线观看 | 91av俱乐部 | 爱情岛av永久入口 | 日日摸日日添日日碰9学生露脸 | 国产精品国产三级国产传播 | 欧美在线小视频 | 男女午夜视频在线观看 | 黄色图片小说 | 久久婷婷一区 | 波多野结衣免费视频观看 | 精品国产免费一区二区三区 | 99热精品在线播放 | 九九热精| 国产精品久久久久久人 | 国产在线观看成人 | 粉嫩av在线播放 | 人人射人人插 | 国产亚洲制服欧洲高清一区 | 波多一区 | 久久精品视频无码 | 久久视频在线免费观看 | 一色屋免费视频 | 精品一区二区三区四 |