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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

KMP POJ 2752 Seek the Name, Seek the Fame

發(fā)布時間:2025/3/8 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 KMP POJ 2752 Seek the Name, Seek the Fame 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

題目傳送門

1 /* 2 題意:求出一個串的前綴與后綴相同的字串的長度 3 KMP:nex[]就有這樣的性質(zhì),倒過來輸出就行了 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-10 11:29:25 8 * File Name :POJ_2752.cpp 9 ************************************************/ 10 11 #include <cstdio> 12 #include <algorithm> 13 #include <iostream> 14 #include <sstream> 15 #include <cstring> 16 #include <cmath> 17 #include <string> 18 #include <vector> 19 #include <queue> 20 #include <deque> 21 #include <stack> 22 #include <list> 23 #include <map> 24 #include <set> 25 #include <bitset> 26 #include <cstdlib> 27 #include <ctime> 28 using namespace std; 29 30 #define lson l, mid, rt << 1 31 #define rson mid + 1, r, rt << 1 | 1 32 typedef long long ll; 33 const int MAXN = 4e5 + 10; 34 const int INF = 0x3f3f3f3f; 35 const int MOD = 1e9 + 7; 36 int nex[MAXN]; 37 char str[MAXN]; 38 39 void get_nex(void) { 40 int len = strlen (str); 41 int i = 0, j = -1; nex[0] = -1; 42 while (i < len) { 43 if (j == -1 || str[j] == str[i]) { 44 j++; i++; nex[i] = j; 45 } 46 else j = nex[j]; 47 } 48 vector<int> ans; 49 while (i != -1) { 50 ans.push_back (i); i = nex[i]; 51 } 52 for (int i=ans.size ()-2; i>=0; --i) { 53 printf ("%d ", ans[i]); 54 } 55 puts (""); 56 } 57 58 int main(void) { //POJ 2752 Seek the Name, Seek the Fame 59 while (scanf ("%s", str) == 1) { 60 get_nex (); 61 } 62 63 return 0; 64 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/Running-Time/p/4717781.html

總結(jié)

以上是生活随笔為你收集整理的KMP POJ 2752 Seek the Name, Seek the Fame的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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