URAL 1297 最长回文子串(后缀数组)

时间序列聚类在股票市场分析中的实践与优化 时间序列聚类是一种面向动态行为建模的无监督学习方法,其核心在于通过语义感知的距离度量(如DTW)捕捉价格形态的相位弹性与结构相似性,而非依赖静态数值或标签驱动。相比K-Means等传统算法,它能有效缓解金融时序中普遍存在的噪声敏感、对齐失效与形态失真问题,从而提升聚类结果的市场可解释性与策略鲁棒性。该技术已广泛应用于市场状态识别、行业行为分群、异常交易监测等场景,并成为构建可验证量化分析框架的关键预处理层。本文聚焦A股真实行情数据,详解从原始OHLCV到可聚类时间序列的完整链路,涵盖DTW距离计算、层次聚类 阅读详情

1297. Palindrome

Time limit: 1.0 second
Memory limit: 64 MB
The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots» security service would have already started an undercover operation to establish the agent’s identity, but, fortunately, the letter describes communication channel the agent uses. He will publish articles containing stolen data to the “Solaris” almanac. Obviously, he will obfuscate the data, so “Robots Unlimited” will have to use a special descrambler (“Robots Unlimited” part number NPRx8086, specifications are kept secret).
Having read the letter, the “U.S. Robots” president recalled having hired the “Robots Unlimited” ex-employee John Pupkin. President knows he can trust John, because John is still angry at being mistreated by “Robots Unlimited”. Unfortunately, he was fired just before his team has finished work on the NPRx8086 design.
So, the president has assigned the task of agent’s message interception to John. At first, John felt rather embarrassed, because revealing the hidden message isn’t any easier than finding a needle in a haystack. However, after he struggled the problem for a while, he remembered that the design of NPRx8086 was still incomplete. “Robots Unlimited” fired John when he was working on a specific module, the text direction detector. Nobody else could finish that module, so the descrambler will choose the text scanning direction at random. To ensure the correct descrambling of the message by NPRx8086, agent must encode the information in such a way that the resulting secret message reads the same both forwards and backwards.
In addition, it is reasonable to assume that the agent will be sending a very long message, so John has simply to find the longest message satisfying the mentioned property.
Your task is to help John Pupkin by writing a program to find the secret message in the text of a given article. As NPRx8086 ignores white spaces and punctuation marks, John will remove them from the text before feeding it into the program.

Input

The input consists of a single line, which contains a string of Latin alphabet letters (no other characters will appear in the string). String length will not exceed 1000 characters.

Output

The longest substring with mentioned property. If there are several such strings you should output the first of them.

Sample

input
ThesampletextthatcouldbereadedthesameinbothordersArozaupalanalapuazorA
output
ArozaupalanalapuazorA


/*
URAL 1297 最长回文子串(后缀数组)

算法合集之《后缀数组——处理字符串的有力工具》:
穷举每一位,然后计算以这个字符为中心的最长回文子串。注意这里要分两
种情况,一是回文子串的长度为奇数,二是长度为偶数。两种情况都可以转化为
求一个后缀和一个反过来写的后缀的最长公共前缀。具体的做法是:将整个字符
串反过来写在原字符串后面,中间用一个特殊的字符隔开。这样就把问题变为了
求这个新的字符串的某两个后缀的最长公共前缀。

所以我们只需先对初始的字符串进行一下处理,然后分别进行奇偶判断得到
最长回文子串的位置和长度

hhh-2016-03-13 15:41:30
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
typedef long double ld;
#define lson (i<<1)
#define rson ((i<<1)|1)
const int maxn = 5005;

int t1[maxn],t2[maxn],c[maxn];
bool cmp(int *r,int a,int b,int l)
{
    return r[a]==r[b] &&r[l+a] == r[l+b];
}

void get_sa(int str[],int sa[],int Rank[],int height[],int n,int m)
{
    n++;
    int p,*x=t1,*y=t2;
    for(int i = 0; i < m; i++) c[i] = 0;
    for(int i = 0; i < n; i++) c[x[i] = str[i]]++;
    for(int i = 1; i < m; i++) c[i] += c[i-1];
    for(int i = n-1; i>=0; i--) sa[--c[x[i]]] = i;
    for(int j = 1; j <= n; j <<= 1)
    {
        p = 0;
        for(int i = n-j; i < n; i++) y[p++] = i;
        for(int i = 0; i < n; i++) if(sa[i] >= j) y[p++] = sa[i]-j;
        for(int i = 0; i < m; i++) c[i] = 0;
        for(int i = 0; i < n; i++) c[x[y[i]]]++ ;
        for(int i = 1; i < m; i++) c[i] += c[i-1];
        for(int i = n-1; i >= 0; i--)  sa[--c[x[y[i]]]] = y[i];

        swap(x,y);
        p = 1;
        x[sa[0]] = 0;
        for(int i = 1; i < n; i++)
            x[sa[i]] = cmp(y,sa[i-1],sa[i],j)? p-1:p++;
        if(p >= n) break;
        m = p;
    }
    int k = 0;
    n--;
    for(int i = 0; i <= n; i++)
        Rank[sa[i]] = i;
    for(int i = 0; i < n; i++)
    {
        if(k) k--;
        int j = sa[Rank[i]-1];
        while(str[i+k] == str[j+k]) k++;
        height[Rank[i]] = k;
    }
}


int mm[maxn];
int dp[20][maxn];
int Rank[maxn],height[maxn];
int sa[maxn],str[maxn];
char ts[maxn];

void ini_RMQ(int n)
{
    mm[0] = -1;
    for(int i = 1;i <= n;i++)
        mm[i] = (((i & (i-1)) == 0) ? mm[i-1]+1:mm[i-1]);

    for(int i =1;i <= n;i++)
        dp[0][i] = height[i];
    for(int i = 1;i <= mm[n];i++)
    {
        for(int j = 1;j+(1<<i)-1 <= n;j++)
        {
            int a = dp[i-1][j];
            int b = dp[i-1][j+(1<<(i-1))];
            dp[i][j] = min(a,b);
        }
    }
}

int askRMQ(int a,int b)
{
    int t = mm[b-a+1];
    b -= (1<<t)-1;
    return min(dp[t][a],dp[t][b]);
}


int fin(int a,int b)
{
    a = Rank[a],b = Rank[b];
    if(a > b) swap(a,b);
    return askRMQ(a+1,b);
}

int main()
{
    while(scanf("%s",ts) != EOF)
    {
        int len = strlen(ts);
        for(int i = 0;i < len;i++)
            str[i] = ts[i];
        str[len] = 1;
        for(int i = 0;i < len;i++)
            str[i+len+1] = ts[len-i-1];
        str[len*2+1] = 0;

        get_sa(str,sa,Rank,height,2*len+1,128);
        ini_RMQ(2*len+1);

        int ans = 0,pos;
        int tp;
        for(int i = 0;i < len;i++)
        {
            tp = fin(i,len*2+1-i);
            if(tp*2 > ans)
            {
                ans = tp*2;
                pos = i-tp;
            }
            tp = fin(i,len*2-i);
            if(tp*2-1 > ans)
            {
                ans = tp*2-1;
                pos = i-tp+1;
            }
        }
        ts[pos+ans] = 0;
        printf("%s\n",ts+pos);
    }
    return 0;
}


【FPGA XDMA AXI Bridge 模式】PCIe:BARs 和 AXI:BARs 含义解析 Xilinx的 DMA/Bridge Subsystem for PCI Express IP核中,支持普通的XDMA模式,但是这种模式只允许主机端发起PCIe 读写请求,FPGA内部无法主动发起读写请求,也即FPGA无法主动读写HOST的内存。而该IP核的另一种模式,AXI Bridge模式则支持HOST主动读写,以及FPGA主动读写。该模式下有个参数需要配置,分别是PCIe:BARs以及AXI:BARs。而上述的普通模式只有PCIe:BARs需要配置。下面详细说说这两个参数的含义。 阅读详情

相关推荐

代码复现——SymAgent:一种用于知识图谱复杂推理的神经符号自学习Agent框架

根据《SymAgent: A Neural-Symbolic Self-Learning Agent Framework for Complex Reasoning over Knowledge Graphs》(《SymAgent:一种用于知识图谱复杂推理的神经符号自学习Agent框架》)论文思路,简单复现代码,以实现SymAgent中的Agent-Planner和Agent-Executor模块。Agent-Planner利用大语言模型的归纳推理能力从知识图谱中提取符号规则,指导高效的问题分解。

qq_60040306的博客 1604

URAL 1297 Palindrome(最长回文子串:后缀数组)

后缀数组的讲解:https://wenku.baidu.com/view/ed1be61e10a6f524ccbf85fd.html 题意: 给你一个字符串,要你求出这个串中的最长回文字串,如果存在多个,则输出第一次出现的那个. 分析: 来自:https://blog.youkuaiyun.com/u013480600/article/details/23946429 首...

pxlsdz的博客 429

从SSTS到CTS:解码汽车电子架构中的需求与实现规范

本文深入解析汽车电子架构中SSTS(子系统功能规范)与CTS(零部件技术规范)的转换过程,揭示从抽象需求到物理实现的关键步骤。通过实际案例说明如何将SSTS的功能逻辑、接口定义和性能指标转化为具体的CTS实施方案,并分享多供应商协同与测试验证的最佳实践,帮助开发者高效完成汽车电子系统开发。

weixin_29201859的博客 498

最长回文子串(后缀数组)

这个也可以利用manacher算法来做 奇数长度的回文串是 从i开始的后缀 与 反转后字符串中从原来的i位子开始的后缀 的公共前缀  偶数长度类似  所以和最长公共子串类似的思路, 将原串S与反转后的S中间加入一个不会出现的字符拼接在一起, 对得到的字符串S’求高度数组  以原来S[i]为中心的奇数长度的回文串长度 = 后缀S’[i…]和后缀 S’[2n-i…]的公共前缀  以原来S[i-1]和...

肘子的博客 1347

3.1使用Python读取excel的二维数据

要使用 Python 读取 Excel 的二维数据,可以使用 openpyxl 或 pandas 库。

kenshin1980的专栏 1032

跟着团子学SAP EPPM:项目管理常见的集成场景(PPM\PS\MS Project)

在SAP的EPPM解决方案中,针对企业战略级别的投资组合管理首先是定义合适的投资组合的层级结构,在投资组合下可以通过不同维度去定义投资篮(Portofolio Bucket)进行层层拆分,在最下层级的投资篮下可以分配明细的投资项(Portofolio Item),投资项可以是独立的一个一个具体执行的项目,也可以是单纯的一次服务等等。 今天主要聚焦在投资项的维度展开讲一下在SAP中投资项常见的几种集成模式: 集成场景1:使用PPM中的Project Management进行项目管理 第一个场景是在创建投资项

Lucas1211的博客 4139

Palindrome

The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots» security s

态度决定高度 533

Amesim与Simulink联合仿真:S-Function接口配置与实战避坑指南

本文详细介绍了Amesim与Simulink联合仿真中S-Function接口的配置方法与实战避坑指南。从环境搭建、编译器配置到S-Function接口实战,逐步解析关键步骤与常见问题解决方案,帮助工程师高效实现多领域系统仿真,特别适合汽车、航空航天等复杂系统建模场景。

weixin_29173777的博客 343

URAL - 1297 最长回文子串

 穷举每一位,然后计算以这个字符为中心的最长回文子串。注意这里要分两种情况,一是回文子串的长度为奇数,二是长度为偶数。两种情况都可以转化为求一个后缀和一个反过来写的后缀的最长公共前缀。具体的做法是:将整个字符串反过来写在原字符串后面,中间用一个特殊的字符隔开。这样就把问题变为了求这个新的字符串的某两个后缀的最长公共前缀。   #include &lt;iostream&gt; #incl...

兜率工的博客 307

火星遥感数据的获取与处理工具安装详解

有关火星遥感影像数据的那些事...

FengYingLuo的博客 5572

单细胞实战之亚细胞分群从T/NK至CD4+T细胞——从入门到进阶(中级篇1)

亚细胞分群从T/NK至CD4+T细胞

zfyyzhys的博客 6389

最长回文(后缀数组||Manacher算法)

转载请注明出处,谢谢http://blog.youkuaiyun.com/acm_cxlove/article/details/7854526       by---cxlove 最长回文是一个经典的例子。 首先是URAL 1297。范围只有1000,可以用后缀数组解决 在原串后面加一个特殊符号之后,将原串反向之后加在后面,然后比较height的最大值。 其中需要判断两个sa,一个在前面一个在后面

窝不是爱酱,喵~~~~ 4215

第五章 TTM 后备管理:5.11 迁移的执行

本文讨论 TTM 框架中缓冲区对象(BO)数据搬运的完整流程,涵盖搬运入口 ttm_bo_handle_move_mem() 的执行步骤、驱动 move 回调的约定、同步辅助函数的使用、多跳迁移机制及异步流水化搬运的处理。重点说明了中转位置的引入原因与执行逻辑,以及通过 ghost 对象和 fence 机制解决异步搬运中的资源释放与访问一致性问题,确保数据安全迁移的同时支持 GPU 异步操作。

图形/计算GPU的驱动与虚拟化技术分享园地 1708

ural 1297 后缀数组 最长回文子串

https://vjudge.net/problem/URAL-1297 题意: 给出一个字符串求最长回文子串 代码: //论文题,把字符串反过来复制一遍到后边,中间用一个没出现的字符隔开,然后就是枚举当以i位置为中间位时的最长回文串 //是多大,就是求这中间的heigh数组的最小值。用rmq预处理。枚举位置时分回文串长度是奇数还是偶数。 #include<iost...

anuancong1219的博客 193

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

【后缀数组】【最长回文子串】Palindrome Ural_1297

Ural_1297. Palindrome Time Limit: 1.0 second Memory Limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots

Jiangzh_MZOI 709

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

ural 1297(求最长回文子串,后缀数组)

1297. PalindromeTime Limit: 1.0 secondMemory Limit: 16 MBThe “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots» security

-- bird -- 2983

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

【后缀数组|最长回文子串】URAL-1297 Palindrome

输入一个字符串,求出它的子串中最长的回文串。

JSure的代码库 1271

ural 1297 Palindrome求最长连续回文子串(后缀数组求法)

ural 1297 Palindrome 题意:很简单,求最长连续回文子串。 解法:这题数据范围非常小,长度只有2000,用dp,n^2可以做,但如果长度变成100000了呢?后缀数组就可以发挥威力了。将原串翻转后接到原串后面,构成一个新的串,枚举前n个字符,设该字符为i,以它为中点的最长回文子串的长度就是。。自己去算算吧,很简单的,注意考虑奇偶。 #include #include #in

No__stop 1139

URAL 1297 Palindrome【后缀数组】求最长回文子串

Description The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. R

Joeferyの博客 964

ural1297 后缀数组扩展,最长回文子串

后缀数组扩展 #include<cstdio> #include<algorithm> #include<iostream> #include<cmath> #include<cstdlib> #include<cstring> #include<string> #include<map> #...

甦萌的博客 273

URAL - 1297 Palindrome —— 后缀数组 最长回文子串

题目链接:https://vjudge.net/problem/URAL-1297 1297. Palindrome Time limit: 1.0 secondMemory limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It stat...

alince20008的博客 180

ural 1297 最长回文子串 后缀数组

http://acm.timus.ru/problem.aspx?space=1&num=1297 1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymo

ACM,再见! 993

Palindrome URAL - 1297 后缀数组求最长回文子串

The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots» security ...

Top_Spirit的博客 338

【URAL】1297 Palindrome 【后缀数组+RMQ——求最长回文子串】

传送门:【URAL】1297 Palindrome 题目分析:将s串倒过来接到原串的后面,中间用'$'隔开,然后我们构造后缀数组和height数组,接着我们RMQ预处理,接下来枚举串的每个点作为回文串的中心,分别以该点为奇回文串中心以及偶回文串中心求LCP,此时向左和向右的串的LCP即以这个点作为中心的回文串的扩展半径,求半径的话我们就对原串位置以及倒过来后的相应位置做LCP。

poursoul 1168

URAL 1297 Palindrome 后缀数组 或 Manacher 求最长回文子串

题目大意: 就是给出一个长度不超过1000个只包含大小写英文字母的字符串,输出其最长回文子串 大致思路: 首先很容易想到用将该字符串本身反转之后与自己连接起来, 中间用一个未出现的字符隔开, 求出后缀数组 刚开始想的是枚举回文串长度,但是发现不能二分判断改长度是否就满足题意, 于是想到一个枚举起点和长度利用RMQ查询和对称性判断的O(n*n)的方法 不过这样并不是最好的枚举方法

Gatevin的专栏 854
上一篇: SPOJ - DISUBSTR 多少个不同的子串
下一篇: poj 2774 最长公共子串 后缀数组
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值