Palindrome(poj3974)(manacher算法)

SOME/IP协议详解「1.1·面向服务与面向信号」 面向信号和面向服务的区别,和举例子 阅读详情
http://poj.org/problem?id=3974
Palindrome
Time Limit: 15000MS Memory Limit: 65536K
Total Submissions: 2707 Accepted: 995
Description


Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient algorithm to find the length of the largest palindrome in a string?" 


A string is said to be a palindrome if it reads the same both forwards and backwards, for example "madam" is a palindrome while "acm" is not. 


The students recognized that this is a classical problem but couldn't come up with a solution better than iterating over all substrings and checking whether they are palindrome or not, obviously this algorithm is not efficient at all, after a while Andy raised his hand and said "Okay, I've a better algorithm" and before he starts to explain his idea he stopped for a moment and then said "Well, I've an even better algorithm!". 


If you think you know Andy's final solution then prove it! Given a string of at most 1000000 characters find and print the length of the largest palindrome inside this string.
Input


Your program will be tested on at most 30 test cases, each test case is given as a string of at most 1000000 lowercase characters on a line by itself. The input is terminated by a line that starts with the string "END" (quotes for clarity). 
Output


For each test case in the input print the test case number and the length of the largest palindrome. 
Sample Input


abcbabcbabcba
abacacbaaaab
END
Sample Output


Case 1: 13
Case 2: 6
Source


Seventh ACM Egyptian National Programming Contest
解析:
题意:求最长回文串长度:
思路:
利用manacher算法计算;
这里简要概述一下这个算法;
总的来说是相邻字符中间插入一个相同的字符构成一新的字符(以此可以避免奇偶性讨论。),然后求以每个点为中心的回文字长度。
就这以下标号来解释一下:
p[i]:以第i个字符为中心的回文长度;
id:前一个回文中心.
mx:前一个回文的最有右端 ,mx=p[id]+id;
1.逐次枚举i判断是否在mx前面,更新p[i]初值;
2.左右看扩展,求当前最大的p[i];
3.更新  id,mx;
4得出的结果为ans=max{p[i]-1};
Accepted 580K 47MS G++ 740B
*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<algorithm>
using namespace std;
const int maxn=1000000+10;
char s[maxn],st[maxn*2];
int p[maxn*2];
void manacher()
{
	int i,j,len;
	len=strlen(s);
	for(i=0,j=0;i<len;i++,j+=2)//构造新数组
	{
		st[j]='#';
		st[j+1]=s[i];
	}
	st[2*len]='#';//末尾处不可忽略
	int mx=0,id;
	for(i=1;i<=2*len;i++)
	{
		if(mx>i)//如果此时的中心点仍在前一个回文串中
		{p[i]=min(p[2*id-i],mx-i);
		}
		else
		p[i]=1;
		//由中心向两边扩展
	for(;st[i-p[i]]==st[i+p[i]]&&(i-p[i]>=0)&&(i+p[i]<=2*len);p[i]++)


	if(mx<i+p[i])//更新mx,id;
	 {
	 	id=i;
	 	mx=i+p[i];
	 }
	}
	int ans=0;
	for(i=1;i<=len*2;i++)//得到最长回文字
	{
		if(p[i]>ans)
		ans=p[i];
	}
	printf("%d\n",ans-1);
}
int main()
{  int ca=0;
	while(scanf("%s",s)!=EOF)
	{
		if(strcmp(s,"END")==0)
		break;
		printf("Case %d: ",++ca);
		manacher();
	}
	return 0;
}


010、Zephyr RTOS开发环境搭建(Docker) 摘要 本文分享了使用Docker搭建Zephyr RTOS开发环境的实践经验。作者通过团队新人配置环境的真实案例,指出传统安装方式存在版本冲突、缓存污染等问题,而Docker方案能确保环境一致性。文章详细介绍了自定义Docker镜像的设计思路,重点解决工具链版本匹配、Python虚拟环境隔离等问题,将镜像体积从2GB优化到800MB。提供了从拉取镜像到点亮LED的完整工作流程,并总结了USB设备直通、文件权限、缓存问题等常见陷阱。还探讨了多阶段构建、CI集成等进阶用法,同时客观分析了Docker方案的局限性 阅读详情

相关推荐

利用Solidworks2020将挖掘机装配体转换为URDF模型

利用Solidworks2020将挖掘机装配体转换为URDF模型一、下载sw_urdf_exporter插件 URDF(Universal Robot Description Format)——通用机器人描述格式,它是ROS里边使用的一种机器人的描述文件,包含的内容有:连杆、关节,运动学和动力学参数、可视化模型、碰撞检测模型等。 一、下载sw_urdf_exporter插件 ROS提供了SolidWorks转URDF的插件(下载链接)—sw2urdfSetup.exe,下载后点击安装,安装完成后就能在sol

weixin_48192326的博客 6118

算法习题篇之Palindrome

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output: true Example 2: Input: -121 Output: false Explana...

灬影的博客 554

中文文本纠错实战:pycorrector与kenlm的安装与高效使用指南

本文提供了一份详细的中文文本纠错实战指南,重点介绍了pycorrector与kenlm的安装与高效使用方法。内容涵盖从编译环境准备、依赖安装到核心参数调优、批量处理及领域自适应等全流程,旨在帮助开发者快速部署并优化纠错系统,提升中文文本处理的质量与效率。

weixin_29055699的博客 427

Palindrome poj3974

Palindrome Time Limit:15000MS Memory Limit:65536K Total Submissions:3280 Accepted:1188 Description Andy the smart computer science student was attending an algorith...

weixin_33725807的博客 338

银河麒麟高级服务器操作系统V10SP2(X86)PXE无人值守批量部署实战指南

本文详细介绍了银河麒麟高级服务器操作系统V10SP2(X86)PXE无人值守批量部署的实战指南。通过PXE网络引导技术,实现全自动化、高效率的系统部署,特别适用于企业级数据中心和国产化替代项目。文章涵盖基础环境准备、关键服务配置、Kickstart高级定制及部署测试等核心内容,帮助用户快速掌握批量部署技巧。

weixin_42525637的博客 393

Spine换装系统深度优化:从局部换肤到动态合批的进阶之路

本文深入探讨了Spine换装系统的性能优化策略,从局部换肤到动态合批的进阶技术。通过分析传统方案的性能瓶颈,提出动态合批、GPU Instancing等高级优化方法,显著降低Draw Call和内存占用,提升游戏性能。适用于MMO和大型游戏开发,帮助技术美术和工程师突破大规模换装场景的性能限制。

vulkan6gpu的博客 558

Palindrome(manacher算法)

PalindromeTime Limit: 15000MS Memory Limit: 65536KTotal Submissions: 11080 Accepted: 4212DescriptionAndy the smart computer science student was attending an algorithms class when the professor asked t...

team39的博客 462

【图像去噪】论文精读:Restormer: Efficient Transformer for High-Resolution Image Restoration

论文题目:Restormer: Efficient Transformer for High-Resolution Image Restoration —— Restormer:用于高分辨率图像恢复的高效变压器高效Transformer模型用于图像恢复!由于卷积神经网络 (CNN) 在从大规模数据中学习可泛化的图像先验方面表现良好,因此这些模型已广泛应用于图像恢复和相关任务。最近,另一类神经架构 Transformer 在自然语言和高级视觉任务中显示出显着的性能提升。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1541

POJ3974 Palindrome回文子串 hash+二分答案做法详解

                           POJ3974 Palindrome回文子串 hash+二分答案做法详解 Time Limit:15000MS Memory Limit:65536K Total Submissions:10983 Accepted:4179 Description Andy the ...

weixin_30475039的博客 309

嵌入式软考必备知识点:嵌入式系统开发中的重要概念和示例代码

在嵌入式软考中,有一些重要的知识点需要掌握,包括嵌入式系统的基本概念、编程语言、实时操作系统和硬件接口等。实时操作系统是一种专门设计用于嵌入式系统的操作系统,可以提供对任务调度、中断处理和资源管理等方面的支持。GPIO(通用输入输出):GPIO是嵌入式系统中常用的硬件接口,用于连接外部设备和嵌入式系统。以上是嵌入式软考中的一些必备知识点,包括嵌入式系统的基本概念、编程语言、实时操作系统和硬件接口。通过配置串口的波特率、数据位数和校验位等参数,可以实现与其他设备的可靠通信。一、嵌入式系统的基本概念。

PixeGO的博客 322

基于MATLAB的语音声强度和响度分析及处理

综上所述,本文介绍了如何使用MATLAB进行语音信号的声强度和响度分析,并提供了相应的源代码。通过这些工具和方法,可以更好地理解和处理语音信号的声强度和响度特性,为语音信号处理和音频应用提供支持。声强度(Intensity)和响度(Loudness)是语音信号中常用的两个重要参数,用于描述声音的强度和感知响度。响度均衡化:可以通过对语音信号施加不同的加权滤波器,调整信号的频谱分布,从而改变声音的响度。除了分析语音信号的声强度和响度,MATLAB还提供了丰富的工具和函数,用于处理语音信号的声强度和响度。

COWizard的博客 629

poj3974 Palindrome (最长回文子串)

Palindrome Time Limit: 15000MS   Memory Limit: 65536K Total Submissions: 2371   Accepted: 864 Description Andy the smart computer science student was attending an algorithm

把复杂的事情简单描述 1003

手把手教你学simulink(26.7)--控制算法场景示例:基于模型预测控制(MPC)的智能温室环境控制系统

首先,我们需要将温室环境的动力学模型转换为状态空间形式。假设我们有四个状态变量:温度 TT、湿度 HH、光照强度 II 和二氧化碳浓度 CCO2CCO2​,以及四个控制输入:加热器功率 u1u1​、加湿器加湿量 u2u2​、通风扇风速 u3u3​ 和补光灯光照强度 u4u4​。状态空间模型可以表示为:x(t)=[T(t),H(t),I(t),CCO2(t)]Tx(t)=[T(t),H(t),I(t),CCO2​(t)]T 是状态向量。

MHD0815的博客 409

POJ 3974 Palindrome

POJ 3974 Palindrome Description Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, “Can you propose an efficient algorit...

旺崽的博客 2427

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

【代码超详解】POJ 3974 Palindrome(Manacher 算法 · 模板)

一、题目描述 二、算法分析说明与代码编写指导 Manacher 算法 注意:fgets 的第二个参数给出的长度需要至少比字符串的最长长度大 2,因为 fgets 会保存换行符 ‘\n’,并在读取到 ‘\n’ 后写 0 结束字符串。如果只比字符串的最长长度大 1,那么当字符串的长度达到最大时,紧跟其后的 ‘\n’ 将不会被读取。下一次 fgets 时会因为读取到了 ‘\n’ 而直接结束读取,导致 ...

COFACTOR 281

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

马拉车算法(Manacher)POJ - 3974 Palindrome

这篇博客不错,大佬 这个视频不错(B站的)也是大佬 POJ - 3974 Palindrome 题意:求最大回文字符串的长度。 马拉车模板 #include<iostream> #include<cstring> #include<string> #include <algorithm> #include"stdio.h" #define MAX_I...

TA很酷的博客 311

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

【Manacher Algorithm】POJ 3974 Palindrome(模板)

礼物不需挑最贵,只要香榭的落叶

L_X_ 252

【POJ 3974】 Palindrome

【题目链接】 http://poj.org/problem?id=3974 【算法】 解法1 : 字符串哈希 我们可以分别考虑奇回文子串和偶回文子串,从前往后扫描字符串,然后二分答案,检验可以用哈希 时间复杂度 : O(TNlog(N)) 解...

165

Manacher - 模板 - Palindrome POJ - 3974

Manacher - 模板 - Palindrome POJ - 3974 题意: 多组测试用例,每组包括一个长度为len的字符串,求该字符串的最大回文子串(包括本身)的长度。多组测试用例,每组包括一个长度为len的字符串,求该字符串的最大回文子串(包括本身)的长度。多组测试用例,每组包括一个长度为len的字符串,求该字符串的最大回文子串(包括本身)的长度。 Sample Input: abcba...

njuptACMcxk的博客 165

manacher板子题 -- Palindrome POJ - 3974

Palindrome POJ - 3974 题意: 多行输入,每次给你一个字符串s(|s| <= 1e6),要你求出s中最长回文串的长度。 思路: manacher板子。 code: #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn = 1e6 + 5; char s[maxn], t[maxn * 2]; int lengh[ma

dajiangyou123456的博客 301

POJ3974【Palindrome】(马拉车模板题)

题目链接:POJ3974【Palindrome】 题目描述: Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, “Can you propose an efficient algorithm to find the length of the largest palindrome in a stri

Obliviate的博客 282

POJ 3974-Palindrome(Manacher算法)

题目地址:POJ 3974 题意:求最长的回文串。 思路:同样是用Mancher算法在O(n)的时间内解决(我其实是来练练板子的#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm

Rocky0429 1777

POJ 3974 Palindrome(Manacher)(板子题)

Description Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient algorithm to find the leng...

weixin_43841060的博客 218

Palindrome POJ - 3974(Manacher)

Andy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient algorithm to find the length of the la...

Top_Spirit的博客 179

poj 3974 Manacher算法

题目链接: http://poj.org/problem?id=3974 Palindrome Time Limit: 15000MS   Memory Limit: 65536K Total Submissions: 13923   Accepted: 5340 Description Andy t...

Source_Roc 248

POJ-3974 Palindrome(manacher算法)

题目链接:点击打开链接 经典的求最长回文子串题目,需要用到manacher算法。 manacher算法的具体介绍:http://blog.csdn.net/ggggiqnypgjg/article/details/6645824 #include #include #include #include #include using namespace std; const int maxn=1

CHeck_Check_check的博客 437
上一篇: Minimum Inversion Number(hdu1394(线段数or暴力))
下一篇: 对拍————快速比较输出结果的异同
lrbj
博客等级 码龄14年 11粉丝 228原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值