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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

hdu 3374 String Problem (字符串最小最大表示 + KMP求循环节)

發布時間:2025/4/16 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 3374 String Problem (字符串最小最大表示 + KMP求循环节) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Problem - 3374 KMP求循環節。 http://www.cnblogs.com/wuyiqi/archive/2012/01/06/2314078.html 循環節推導的證明相當的好,這題是很裸的套算法的題。 代碼如下: 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 6 using namespace std; 7 8 const int N = 1111111; 9 char buf[N]; 10 int next[N]; 11 12 void getNext(char *str) { 13 char *si = str; 14 int *ni = next; 15 int j = *next = -1; 16 while (*si) { 17 while (j > -1 && *si != *(str + j)) j = *(next + j); 18 si++, ni++, j++; 19 // if (*si == *(str + j)) *ni = *(next + j); 20 // else *ni = j; 21 *ni = j; 22 } 23 } 24 25 int minMaxExp(char *s, bool mini) { 26 int i = 0, j = 1, k = 0, t; 27 int len = strlen(s); 28 while (i < len && j < len && k < len) { 29 // cout << i << ' ' << j << ' ' << k << endl; 30 t = s[(i + k) % len] - s[(j + k) % len]; 31 if (!t) k++; 32 else { 33 if (mini ^ (t > 0)) j += k + 1; 34 else i += k + 1; 35 if (i == j) j++; 36 k = 0; 37 } 38 } 39 return min(i, j); 40 } 41 42 int main() { 43 while (cin >> buf) { 44 getNext(buf); 45 // for (int i = 0, sz = strlen(buf); i < sz; i++) cout << next[i] + 1 << ' '; cout << endl; 46 int cycle = strlen(buf); 47 // cout << "got next" << endl; 48 cycle /= (cycle - next[cycle - 1] - 1); 49 cout << minMaxExp(buf, true) + 1 << ' ' << cycle << ' ' << minMaxExp(buf, false) + 1 << ' ' << cycle << endl; 50 } 51 return 0; 52 } View Code

?

——written by Lyon

轉載于:https://www.cnblogs.com/LyonLys/p/hdu_3374_Lyon.html

總結

以上是生活随笔為你收集整理的hdu 3374 String Problem (字符串最小最大表示 + KMP求循环节)的全部內容,希望文章能夠幫你解決所遇到的問題。

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