Z.Theme Section

Problem Description
It’s time for music! A lot of popular musicians are invited to join us in the music festival. Each of them will play one of their representative songs. To make the programs more interesting and challenging, the hosts are going to add some constraints to the rhythm of the songs, i.e., each song is required to have a ‘theme section’. The theme section shall be played at the beginning, the middle, and the end of each song. More specifically, given a theme section E, the song will be in the format of ‘EAEBE’, where section A and section B could have arbitrary number of notes. Note that there are 26 types of notes, denoted by lower case letters ‘a’ - ‘z’.

To get well prepared for the festival, the hosts want to know the maximum possible length of the theme section of each song. Can you help us?

Input
The integer N in the first line denotes the total number of songs in the festival. Each of the following N lines consists of one string, indicating the notes of the i-th (1 <= i <= N) song. The length of the string will not exceed 10^6.

Output
There will be N lines in the output, where the i-th line denotes the maximum possible length of the theme section of the i-th song.

Sample Input
5
xy
abc
aaa
aaaaba
aaxoaaaaa

Sample Output
0
0
1
1
2

题解:

没想到这题这么水。
先用next数组求出最长的前后缀长度。
之后暴力枚举即可。每次把前后缀长度减一,看字符串内部有无此字符。
47ms

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <windows.h>
using namespace std;

const int maxn = 1e6+100;
int nt[maxn];
int len;
char s[maxn];

void getNext()
{
    int j,k;
    j=0;k=-1;nt[0]=-1;
    while(j<len)
    {
        if(k==-1||s[j]==s[k])
            nt[++j]=++k;
        else
            k=nt[k];
    }
}
char tmp[maxn];

int main()
{
    int N;
    scanf("%d",&N);
    while(N--)
    {
        scanf("%s",s);
        len = strlen(s);
        getNext();
        if(nt[len]==0)
        {
            cout<<0<<endl;
            continue;
        }
         int l=nt[len],pos;
         while(1)
         {
              int i;
              for(i=0;i<l;i++)
              {
                  tmp[i]=s[i];
              }
              tmp[i]='\0';
              pos =strstr(s+l,tmp)-s;

              if(pos<len-l&&pos>=l) break;

              l--;
         }
         cout<<l<<endl;
    }
    return 0;
}
### 回答1: 要添加tlagent.wpf.theme,首先需要确保计算机已经安装了相应的WPF主题。然后,按照以下步骤进行操作: 1. 打开Visual Studio开发环境,并打开你想要添加tlagent.wpf.theme的项目。 2. 在项目资源管理器中,找到项目中的References(引用)文件夹。 3. 右键单击References(引用)文件夹,并选择“添加引用”。 4. 在弹出的“添加引用”对话框中,点击左侧的“浏览”按钮。 5. 在浏览对话框中,找到包含tlagent.wpf.theme的程序集文件(通常是.dll文件),然后点击“确定”按钮。 6. 返回“添加引用”对话框,在右侧的引用列表中,确保已经选中了tlagent.wpf.theme。 7. 点击“确定”按钮,将tlagent.wpf.theme添加到项目的引用中。 8. 现在,你可以在项目中使用tlagent.wpf.theme的功能和样式。 需要注意的是,确保你使用的tlagent.wpf.theme版本与你的项目兼容,并且遵循适当的授权和使用法律法规。此外,根据具体情况,你可能还需要进行其他设置或配置来正确地使用tlagent.wpf.theme。 ### 回答2: 要添加tlagent.wpf.theme,可以按照以下步骤进行操作: 1. 首先,确保你已经安装了相关的开发环境和工具,比如Visual Studio等。 2. 打开你的项目,并定位到“引用”(References)部分,右键点击并选择“管理NuGet程序包”(Manage NuGet Packages)。 3. 在NuGet Packages窗口的搜索框中输入“tlagent.wpf.theme”,点击搜索按钮。 4. 在搜索结果中找到并选择正确的tlagent.wpf.theme包。务必仔细查看包的描述、版本等信息,确保选择与你的项目兼容的正确版本。 5. 点击“安装”(Install)按钮,等待包的下载和安装过程完成。 6. 安装完成后,tlagent.wpf.theme的库文件和相关资源文件将会被添加到你的项目中。 7. 现在,你可以在你的项目中使用tlagent.wpf.theme提供的样式和主题了。可以通过在XAML代码中引用其命名空间,或者直接在代码中使用相关的样式和控件。 总之,通过使用NuGet包管理器来添加tlagent.wpf.theme,你可以方便地将其集成到你的项目中,以实现样式和主题的定制和使用。不过,请注意选择正确的版本和确保其与你的项目兼容。 ### 回答3: 要添加tlagent.wpf.theme,可以按照以下步骤进行操作: 1. 首先,在电脑上找到已安装的tlagent.wpf.theme文件。这个文件通常以.dll后缀结尾。如果你没有这个文件,可以在互联网上搜索并下载。 2. 找到你希望添加tlagent.wpf.theme的项目。这可以是一个已经存在的WPF项目,或者是一个新建的项目。 3. 打开你的项目,在项目中找到对应的引用文件夹(References folder)。 4. 右击引用文件夹,在弹出的菜单中选择“添加引用”(Add Reference)选项。 5. 在添加引用的对话框中,选择“浏览”(Browse)选项卡。 6. 浏览你的电脑,找到tlagent.wpf.theme文件并选择它。 7. 点击“确定”(OK)按钮,将tlagent.wpf.theme添加到你的项目中。 8. 确保你的项目中的相关代码正确地使用tlagent.wpf.theme中的类和方法。你可以通过在代码中调用相关的命名空间和类来使用tlagent.wpf.theme。 总之,添加tlagent.wpf.theme需要找到该文件并将其添加到项目的引用中。在添加引用后,确保正确使用相关代码即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值