一、题目描述
二、算法分析说明与代码编写指导
Manacher 算法
注意:fgets 的第二个参数给出的长度需要至少比字符串的最长长度大 2,因为 fgets 会保存换行符 ‘\n’,并在读取到 ‘\n’ 后写 0 结束字符串。如果只比字符串的最长长度大 1,那么当字符串的长度达到最大时,紧跟其后的 ‘\n’ 将不会被读取。下一次 fgets 时会因为读取到了 ‘\n’ 而直接结束读取,导致 WA。
三、AC 代码
#include<cstdio>
#include<algorithm>
#include<cstring>
#pragma warning(disable:4996)
using namespace std;
template<class _Ty> inline void manacher(const char* const s, const _Ty& L, _Ty* const d1, _Ty* const d2) {
_Ty i, k, l, r;
for (i = 1, l