poj 2752 Seek the Name, Seek the Fame

智能车图像处理去畸变+逆透视教程 图像处理,去畸变与逆透视整合 阅读详情

Seek the Name, Seek the Fame
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 12866 Accepted: 6346

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

题目大意:给定一个字符串,求其相同前缀后缀的长度,由小到大输出所有情况。


解题思路:用kmp算法的next数组。由分析可知,整串字符串的相同前缀后缀中,若前缀子串有相同的前缀后缀,则

前缀子串的后缀一定等于后缀子串的后缀,即整串字符串有更小的相同前缀后缀,以此类推,可由大到小得出所有结果。


代码如下:

#include <cstdio>
#include <cstring>
int const maxn=400010;
char s[maxn];
int next[maxn];
int a[maxn];  //int a[maxn]; 
int len;
void get_next()
{
    int i=0,j=-1;
    next[0]=-1;
    while(i<len)
    {
        if(j==-1||s[i]==s[j])
        {
            i++;
            j++;
            next[i]=j;
        }
        else
            j=next[j];
    }
}

int main()
{
    int cur;
    while(scanf("%s",s)!=EOF)
    {
        int i=0;
		memset(a,0,sizeof(a));
        len=strlen(s);
        cur=len;
        a[0]=len;   //初始前缀长度一定为字符串长度
        get_next();
        while(cur)
        {
           a[++i]=next[cur];  //  next[前缀长度]即为前缀子串的前缀长度,直到next[]值为0是结束循环
           cur=a[i];
		}
        for(int j=i-1;j>=0;j--)
            printf("%d ", a[j]);
		printf("\n");
    }
    return 0;
}



Quartus的Signal Tap II的使用技巧 Signal Tap II全称Signal Tap II Logic Analyzer,是第二代系统级调试工具,它集成在Quartus II软件中,可以捕获和显示实时信号,是一款功能强大、极具实用性的FPGA片上调试工具软件。传统的FPGA板级调试是由外接的逻辑分析仪连接到FPGA的控制引脚,将内部引号引出至引脚I/O上,接着进行板级调试。 阅读详情

相关推荐

【Java】对接微信转账到零钱接口 Java微信商家转账 apiV3(该踩的雷都踩了)

配置apiv3依赖java代码。

Moonhwa的博客 4316

POJ 2752 Seek the Name, Seek the Fame(KMP)

POJ 2752 Seek the Name, Seek the FameDescriptionThe 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. T

This is Mendez. 702

[漏洞利用]利用五次Shift越权破解win7\win10开机密码

注:第一个学习和接触的Windows漏洞 文章目录本机实验环境前置知识漏洞原理漏洞介绍漏洞验证解决方法基本流程介绍详细步骤截图 本机实验环境 虚拟机:VMware Workstation 14 pro 操作系统:Windows10 前置知识 1、cmd工具路径 c:\windows\system32\cmd,按五次shift默认调用同目录下sethc文件,其路径为“c:\windows\system32\sethc.exe” 2、用户/账户密码存储位置 c:\windows\system32\config\

Y4tacker的博客 2万+

哈希 poj2752 Seek the Name, Seek the Fame

Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17568   Accepted: 9009 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland,

fanesemyk的博客 461

【报错】sqli-labs靶场搭建出现“Unable to connect to the database: security”

搭建sqli-labs靶场时,“Unable to connect to the database: security”报错解决

九芒星的博客 2988

STM32F407编译下载全流程:从CubeMX到HEX烧录

嵌入式固件开发中,编译与下载是连接代码与硬件的关键闭环。其本质是将高级语言描述的逻辑,经交叉编译(ARM GCC)、链接(ELF生成)、格式转换(HEX/BIN)后,通过调试接口(SWD/UART)写入MCU Flash存储器的过程。该流程涉及工具链协同、二进制格式特性(如Intel HEX的地址映射与无元数据设计)、启动模式(System Memory Bootloader)、Flash选项字节(RDP/WRP)等底层机制,直接决定固件可运行性与安全性。典型应用场景包括STM32F407开发板调试、量产固

weixin_28840811的博客 259

poj 2752 Seek the Name, Seek the Fame (KMP)

题目链接:  poj 2752 题目大意:  给出字符串,找出所有的前缀和后缀相等的子串                   按小到大输出这些子串的长度 解题思路:                                  如图所示,根据next[  ]前缀的性质左边有颜色部分和右边有颜色部分完全相等                   因为左边的红色和右边的红色相等,

ンZee的解题报告 2456

拆开华为BBU5900,看看5G基站的大脑里到底装了啥?

本文深度拆解华为BBU5900,揭示5G基站核心处理单元的硬件架构与设计哲学。通过详细解析模块化设计、智能电源系统和动态散热方案,展现其支撑千兆速率、毫秒级时延的技术奥秘,为5G网络部署提供实用参考。

weixin_31456563的博客 557

POJ 2752 Seek the Name, Seek the Fame

DescriptionThe 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 ti

Monster_Day的博客 7826

Python爬虫实战:使用最新技术爬取新华网新闻数据

在当今信息爆炸的时代,网络爬虫技术已经成为获取互联网数据的重要手段。作为国内权威新闻媒体,新华网每天发布大量高质量的新闻内容,这些数据对于舆情分析、市场研究、自然语言处理等领域具有重要价值。本文将详细介绍如何使用Python最新技术构建一个高效、稳定的新华网新闻爬虫系统。本文详细介绍了如何使用Python最新技术栈构建一个高效、稳定的新华网新闻爬虫系统。我们从基础爬虫开始,逐步添加了代理支持、用户代理轮换、请求延迟、重试机制、动态页面渲染、数据存储等高级功能,最终实现了一个生产可用的分布式爬虫系统。

2201_76125261的博客 1770

天龙八部TLBB系列 - 网单用数据库修改为其他门派

专注于Android/Unity和各种游戏开发技巧,以及各种资源分享(网站、工具、素材、源码、游戏等) --- 天龙八部修改门派

空名先生 9429

POJ 2752:Seek the Name, Seek the Fame

Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13619 Accepted: 6755Description The little cat is so famous, that many couples tramp over hill and

785

NSIS教程(6): 使用第三方插件

NSIS内置了很多指令,这些指令可以满足我们基本需求,但难免会遇到NSIS没有内置的功能,如进程操作,后台运行(即多线程),7z压缩等等,这个时候我们就需要借助第三方插件来满足我们所需要的功能了。 一、插件获取 NSIS官方收录插件的网址是:http://nsis.sourceforge.net/Category:Plugins,我们可以在这个网站上查找和下载我们需要的插件,该网站上针对每

while(1) { smile(); } 9万+

POJ2752 Seek the Name, Seek the Fame【KMP】

POJ2752 Seek the Name,Seek the FamePOJ2752\ Seek\ the\ Name, Seek\ the\ FamePOJ2752 Seek the Name,Seek the Fame 【简要题意】 给定一个字符串,从小到大输出sss中既是前缀又是后缀的子串长度 【题解】 KMPKMPKMP比较裸的题,考察对KMPKMPKMP里nxtnxtnxt数组的理解 借用KMPKM

Young_Zn_Cu 140

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

POJ2752 Seek the Name, Seek the Fame

POJ2752 Seek the Name, Seek the Fame 本题是求一个fail数组就可以了 但是这一题有一个地方和fail数组定义不同:它自身也算一个最长公共前后缀 这一点想了很久。。。。但是最终发现不用改变fail数组,只需要多输出一个字符串它自己的长度就可以了(因为根据题目定义字符串本身必定是它自己的最长公共前后缀) 由于他要升序,把他丢到一个优先队列就行了 代码: #incl...

AlexTYJ的博客 152

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

poj2752 Seek the Name,Seek the Fame

KMP

AaronPolaris 1617

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

POJ 2752 Seek the Name,Seek the Fame

Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14048   Accepted: 6990 Description The little cat is so famous, that many coup

Moressette流沙的博客 408

【POJ2752】Seek the Name, Seek the Fame(hash)

题目地址:http://poj.org/problem?id=2752 题目: 每组数据给定一个字符串,从小到大输出既是前缀又是后缀的子串的长度 ac代码: 直接用hash做,比kmp简单很多 #include <cmath> #include <iostream> #include <cstdio> #include <string&g...

Cassie_zkq的博客 228

poj 2752 Seek the Name, Seek the Fame 哈希

Seek the Name, Seek the Fame Time Limit:2000MS Memory Limit:65536K Total Submissions:25503 Accepted:13255 Description The little cat is so famous, that many couples tramp ove...

喵喵喵 401

POJ 2752 Seek the Name, Seek the Fame

原题: Seek the Name, Seek the Fame   原题意思:输入一串全为小写字母的字符串,字符串长度小于400000,输出所有满足前缀和后缀相等的字符的长度,这个”组合条件“我会在样例中说明。 第一组样例解释: 样例一:ababcababababcabab 2:ababcababababcabab 4:ababcabababcaba

CS33sun的博客 424

poj 2752 Seek the Name, Seek the Fame

http://poj.org/problem?id=2752 Seek the Name, Seek the Fame Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give

大太阳 410

POJ 2752 Seek the Name, Seek the Fame (KMP)

Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17250   Accepted: 8816 Description The little cat is so famous, that many couple

MADE_Y 700
上一篇: poj 2406 Power Strings
下一篇: poj 3461 Oulipo
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值