Replies: 12 comments 2 replies
-
全文引用洛咕日报#80? |
Beta Was this translation helpful? Give feedback.
-
建议修改页面使之适应Wiki风格 |
Beta Was this translation helpful? Give feedback.
-
@ZhangBo1191 作者是同一个人,谢谢 |
Beta Was this translation helpful? Give feedback.
-
@ZhangBo1191 本页面内容已经重写了,谢谢提醒 |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
确实和Z函数的算法思路完全一样,看懂了一个,另一个马上就明白了。 代码和z函数统一风格的话是: 奇数回文 vector<int> d1(n);
fill(d1.begin(), d1.end(), 1);
for(int i = 0, l = 0, r = 0; i < n; i++) {
if (i <= r) d1[i] = min(d1[l + r - i], r - i + 1);
while (d1[i] < i + 1 && i + d1[i] < n && s[i - d1[i]] == s[i + d1[i]]) ++d1[i];
if (i + d1[i] - 1 > r) l = i + 1 - d1[i]; r = i + d1[i] - 1;
} 偶数回文 vector<int> d2(n);
for (int i = 1, l = 0, r = 0; i < n; i++) { // 偶数回文要求至少有s[i], s[i - 1] 存在
if (i <= r) d2[i] = min(d2[l + r - i + 1], r - i + 1);
while (d2[i] < i && i + d2[i] < n && s[i - d2[i] - 1] == s[i + d2[i]]) ++d2[i];
if (i + d2[i] - 1 > r) l = i - d2[i]; r = i + d2[i] - 1;
} 我觉得哪怕是原型算法里最好也不要随便用负值,因为实践里要都要换成 unsigned |
Beta Was this translation helpful? Give feedback.
-
代码和英文翻译版似乎不一样,请留意 @Ir1d |
Beta Was this translation helpful? Give feedback.
-
计算d1的代码有个地方有问题: |
Beta Was this translation helpful? Give feedback.
-
改不改都一样好吧,只是一个理解 |
Beta Was this translation helpful? Give feedback.
-
https://oi-wiki.org/string/hash/#%E6%9C%80%E9%95%BF%E5%9B%9E%E6%96%87%E5%AD%90%E4%B8%B2 |
Beta Was this translation helpful? Give feedback.
-
https://oi-wiki.org/string/manacher/
Beta Was this translation helpful? Give feedback.
All reactions