POJ-2752 Seek the Name,Seek the Fame

本文介绍了一种用于解决字符串S的特定子串问题的高效算法。该算法通过构建字符串S的前缀数组来快速找出所有既是S的前缀也是其后缀的子串长度,并按升序输出这些长度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接

http://poj.org/problem?id=2752

题目

Seek the Name, Seek the Fame
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 21465 Accepted: 11207
Description

The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names to their newly-born babies. They seek the name, and at the same time seek the fame. In order to escape from such boring job, the innovative little cat works out an easy but fantastic algorithm:

Step1. Connect the father’s name and the mother’s name, to a new string S.
Step2. Find a proper prefix-suffix string of S (which is not only the prefix, but also the suffix of S).

Example: Father=’ala’, Mother=’la’, we have S = ‘ala’+’la’ = ‘alala’. Potential prefix-suffix strings of S are {‘a’, ‘ala’, ‘alala’}. Given the string S, could you help the little cat to write a program to calculate the length of possible prefix-suffix strings of S? (He might thank you by giving your baby a name:)
Input

The input contains a number of test cases. Each test case occupies a single line that contains the string S described above.

Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.
Output

For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby’s name.
Sample Input

ababcababababcabab
aaaaa
Sample Output

2 4 9 18
1 2 3 4 5

题意

给定一个字符串S,求字串T的长度length。将length按升序输出。
字串T满足:T是S的前缀,同时T还是S的后缀。

题解

考虑字符串S的前缀数组pre,pre[i]=j表示S[1..j]=S[i-j+1..i]。定义len为S的长度,x=pre[len]显然是一个解。因为S[1..x]=S[len-x+1..len],所以S[1..pre[x]]=S[len-pre[i]+1..len],也就是说pre[x]也是一个解。
综上,length=pre[len]、pre[pre[len]]…

代码

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn=4e5+100;
int n,ans[maxn],tot,pre[maxn];
char t[maxn];

void getpre()
{
    int j=0;
    memset(pre,0,sizeof(pre));
    for(int i=2;i<=n;i++)
    {
        while(j>0 && t[j+1]!=t[i]) j=pre[j];
        if(t[j+1]==t[i]) j++;
        pre[i]=j;
    }
}

int main()
{
    while(~scanf("%s",t+1))
    {
        n=strlen(t+1);
        getpre();
        memset(ans,0,sizeof(ans));
        tot=0;
        ans[tot]=n;
        for(int i=n;pre[i];i=pre[i])
        {
            int v=pre[i];
            ans[++tot]=v;
        }
        sort(ans,ans+tot+1);
        for(int i=0;i<=tot;i++)
        {
            printf("%d%s",ans[i],i==tot?"\n":" ");
        }
    }
    return 0;
}
内容概要:该博士论文深入研究了新型电力系统中构网型变流器的功角暂态特性量化理论。针对现有研究在装备过流能力设计和系统暂态稳定评估方面的不足,论文提出了基于平均思想和渐进思想的功角暂态运行轨迹解析方法,解决了强阻尼耗散系统轨迹求解难题;同时提出了单机和两机系统的暂态阻尼能量可视化与定量化分析方法,实现了暂态稳定边界的精确刻画。研究不仅为电力电子化电力系统中装备与电网的双向适配提供了理论基础,还通过Python代码复现了核心理论,包括功角暂态轨迹解析、暂态阻尼能量分析、两机系统非均匀阻尼分析等,验证了方法的有效性和实用性。 适合人群:从事电力系统研究和开发的专业人员,特别是关注电力电子化电力系统中构网型变流器暂态特性的工程师和研究人员。 使用场景及目标:①理解构网型变流器在强阻尼条件下的功角暂态特性;②掌握功角暂态轨迹解析方法(如KB平均法和KBM渐进法)及其改进;③学习如何通过可视化手段分析暂态阻尼能量;④探索两机系统非均匀阻尼对系统稳定性的影响;⑤利用量化理论优化电力系统的过流设计和暂态稳定评估。 其他说明:本文档不仅提供了详细的理论分析,还附带了完整的Python代码实现,使读者能够通过代码实践加深对理论的理解。此外,文档还讨论了未来的研究方向,如多时间尺度耦合分析、高比例电力电子系统稳定性等,为后续研究提供了参考。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值