国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

hihocoder1032:(manacher)

2019-11-08 03:05:40
字體:
來源:轉載
供稿:網友

題目:http://hihocoder.com/PRoblemset/problem/1032

題目分析:manacher模板,RE了好多次。一開始是數組忘了開兩倍長度,接下來又是多算了最后一位的答案導致數組越界(即’$’),重點是忘了寫“if( i+temp[i]>p+temp[p] ) p=i;”這句如此重要的話……輸出答案的時候要注意分類討論一下。

CODE:

#include<iostream>#include<string>#include<cstring>#include<cmath>#include<cstdio>#include<cstdlib>#include<stdio.h>#include<algorithm>using namespace std;const int maxn=1000100;int temp[maxn<<1];string t,s;int n;int main(){	freopen("c.in","r",stdin);	freopen("c.out","w",stdout);		scanf("%d",&n);	for (int q=1; q<=n; q++)	{		cin>>t;		int tlen=t.size()-1;				s="";		s+='@';		for (int i=0; i<tlen; i++)		{			s+=t[i];			s+='#';		}		s+=t[tlen];		s+='$';				int slen=s.size();		int p=1,ans=0;		temp[0]=temp[1]=0;		for (int i=2; i<slen; i++)		{			temp[i]=max( 0,min( temp[2*p-i],p+temp[p]-i ) );			while ( s[i+temp[i]]==s[i-temp[i]-2] ) temp[i]++;			if ( i+temp[i]>p+temp[p] ) p=i;			if (s[i-1]=='#') ans=max(ans, temp[i]+(temp[i])%2 );			else ans=max(ans, temp[i]+(temp[i]-1)%2 );		}				printf("%d/n",ans);	}		return 0;}
上一篇:文章標題

下一篇:c語言之單鏈表

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌拉特后旗| 五家渠市| 昆山市| 汉中市| 兰坪| 孟村| 东源县| 亚东县| 区。| 金寨县| 曲麻莱县| 临夏县| 孙吴县| 旺苍县| 思茅市| 白朗县| 平湖市| 额尔古纳市| 马尔康县| 娄底市| 名山县| 龙山县| 饶阳县| 泾阳县| 上饶县| 临颍县| 凌海市| 寿光市| 嫩江县| 五寨县| 霍州市| 铜鼓县| 盐边县| 诸城市| 北宁市| 沙雅县| 龙海市| 花莲县| 金寨县| 上饶市| 淮滨县|