标签:space 字符 string -o 没有 tar using main targe
https://blog.csdn.net/qq_16554583/article/details/79763296
https://blog.csdn.net/qq_41923622/article/details/80109897
//马拉车算法基础模板,求最长的回文半径。
//其中init函数是把原来的字符串每个字母中间插入一个串里没有出现过的字符,其中这个字符从1开始,0的位置也用一个没出现过的字符代替。
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxm = 3e5; char s[maxm], str[maxm]; int len1, len2, p[maxm], ans; void init() { str[0] = ‘*‘; str[1] = ‘#‘; for(int i = 0; i < len1; i++) { str[2 * i + 2] = s[i]; str[2 * i + 3] = ‘#‘; } len2 = len1 * 2 + 2; //str[len2] = ‘&‘; } void manacher() { int id = 0, mx = 0; for(int i = 1; i < len2; i++) { if(mx > i) p[i] = min(p[2 * id - i], mx - i); else p[i] = 1; for(; str[i + p[i] ] == str[i - p[i] ]; p[i]++); if(p[i] + i > mx) { mx = p[i] + i; id = i; } } } int main() { while(~scanf("%s", s)) { len1 = strlen(s); init(); manacher(); ans = 0; for(int i = 0; i < len2; i++) { ans = max(ans, p[i]); } printf("%d\n", ans - 1); } return 0; }
标签:space 字符 string -o 没有 tar using main targe
原文地址:https://www.cnblogs.com/downrainsun/p/10447249.html