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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

HDU 3068 最长回文

發(fā)布時間:2025/3/14 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 3068 最长回文 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

最長回文串模板題

Manacher 算法

1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 #include<cstdlib> 6 #include<string> 7 #include<cmath> 8 #include<vector> 9 using namespace std; 10 const int maxn=1e5+7; 11 const double eps=1e-8; 12 const double pi=acos(-1); 13 #define ll long long 14 #define clc(a,b) memset(a,b,sizeof(a)) 15 16 int Proc(char pszIn[],char pszOut[]) 17 { 18 int nLen=1; 19 pszOut[0]='$'; 20 int i=0; 21 while(pszIn[i]!='\0') 22 { 23 pszOut[nLen++]='#'; 24 pszOut[nLen++]=pszIn[i]; 25 i++; 26 } 27 pszOut[nLen++]='#'; 28 pszOut[nLen]=0; 29 return nLen; 30 } 31 void Manacher(int *p,char *str,int len) 32 { 33 int mx=0,id=0; 34 for(int i=0; i<len; i++) 35 { 36 p[i]=mx>i?min(p[2*id-i],mx-i):1; 37 while(str[i+p[i]]==str[i-p[i]])p[i]++; 38 if(i+p[i]>mx) 39 { 40 mx=i+p[i]; 41 id=i; 42 } 43 } 44 } 45 const int MAXN=220010; 46 char strIn[MAXN]; 47 char strOut[MAXN]; 48 int p[MAXN]; 49 int main() 50 { 51 while(scanf("%s",strIn)!=EOF) 52 { 53 int nLen=Proc(strIn,strOut); 54 Manacher(p,strOut,nLen); 55 int ans=1; 56 for(int i=0; i<nLen; i++) 57 ans=max(ans,p[i]); 58 printf("%d\n",ans-1); 59 } 60 return 0; 61 } View Code

?

轉載于:https://www.cnblogs.com/ITUPC/p/5243790.html

總結

以上是生活随笔為你收集整理的HDU 3068 最长回文的全部內容,希望文章能夠幫你解決所遇到的問題。

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