51nod1088(最长回文子串)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1088
题意: 中文题目诶~
思路: 这道题字符串长度限定为1e3, 所以O(n^2)也能过啦~
那么我们直接枚举所有中间位置的字符,然后取得最大值就好了啦;
注意将子串长度分下奇偶.
代码:
#include <bits/stdc++.h>
#define MAXN 1010
using namespace std; int main(void){
char ch[MAXN];
int m=, l;
scanf("%s", ch);
l=strlen(ch);
for(int i=; i<l; i++){ //i表中间子串的中间位置
for(int j=; i-j>=&&j+i<l; j++){ //子串长度为奇数的情况, j表对称位置的长度
if(ch[i-j]!=ch[i+j]){
break;
}else{
m=max(m, *j+);
}
}
for(int j=; i-j>=&&i+j+<l; j++){ //子串长度为偶数的情况, j表左边中间位置到开始位置的长度
if(ch[i-j]!=ch[i+j+]){
break;
}else{
m=max(m, *j+);
}
}
}
printf("%d\n", m);
return ;
}
51nod1088(最长回文子串)的更多相关文章
- 最长回文子串-LeetCode 5 Longest Palindromic Substring
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...
- 最长回文子串(Longest Palindromic Substring)
这算是一道经典的题目了,最长回文子串问题是在一个字符串中求得满足回文子串条件的最长的那一个.常见的解题方法有三种: (1)暴力枚举法,以每个元素为中心同时向左和向右出发,复杂度O(n^2): (2)动 ...
- lintcode最长回文子串(Manacher算法)
题目来自lintcode, 链接:http://www.lintcode.com/zh-cn/problem/longest-palindromic-substring/ 最长回文子串 给出一个字符串 ...
- 1089 最长回文子串 V2(Manacher算法)
1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 回文串是指aba.abba.cccbccc.aaaa ...
- 51nod1089(最长回文子串之manacher算法)
题目链接: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1089 题意:中文题诶~ 思路: 我前面做的那道回文子串的题 ...
- 求最长回文子串:Manacher算法
主要学习自:http://articles.leetcode.com/2011/11/longest-palindromic-substring-part-ii.html 问题描述:回文字符串就是左右 ...
- [译+改]最长回文子串(Longest Palindromic Substring) Part II
[译+改]最长回文子串(Longest Palindromic Substring) Part II 原文链接在http://leetcode.com/2011/11/longest-palindro ...
- [译]最长回文子串(Longest Palindromic Substring) Part I
[译]最长回文子串(Longest Palindromic Substring) Part I 英文原文链接在(http://leetcode.com/2011/11/longest-palindro ...
- Manacher's algorithm: 最长回文子串算法
Manacher 算法是时间.空间复杂度都为 O(n) 的解决 Longest palindromic substring(最长回文子串)的算法.回文串是中心对称的串,比如 'abcba'.'abcc ...
随机推荐
- java中hashcode()和equals()的详解
今天下午研究了半天hashcode()和equals()方法,终于有了一点点的明白,写下来与大家分享(zhaoxudong 2008.10.23晚21.36). 1. 首先equals()和hashc ...
- JQuery对id中含有特殊字符的转义处理
转载--http://www.jb51.net/article/41192.htm <div id="a[]">kkkkkk</div> <scrip ...
- 运维自动化轻量级工具pssh
1pssh介绍 pssh是python写的可以并发在多台机器上批量执行命令的工具,它的用法可以媲美ansible的一些简单用法,执行起来速度比ansible快它支持文件并行复制,远程命令执行,杀掉远程 ...
- Sphinx在windows上的安装使用
Sphinx是一个基于SQL的全文检索引擎,可以结合MySQL,PostgreSQL做全文搜索, 它可以提供比数据库本身更专业的搜索功能,使得应用程序更容易实现专业化的全文检索. Sphinx特别为一 ...
- 使用Python进行描述性统计
目录 1 描述性统计是什么?2 使用NumPy和SciPy进行数值分析 2.1 基本概念 2.2 中心位置(均值.中位数.众数) 2.3 发散程度(极差,方差.标准差.变异系数) 2.4 偏差程度(z ...
- Cocos2d-x 3.X 事件分发机制
介绍 Cocos2d-X 3.X 引入了一种新的响应用户事件的机制. 涉及三个基本的方面: Event listeners 封装你的事件处理代码 Event dispatcher 向 listener ...
- DialogFragment is gone after returning back from another activity
基本情景如下: 在DialogFragment中单击一个按钮跳转到another Activity做一些逻辑处理,然后将返回的结果回显到该DialogFragment上. 处理逻辑是: 在Dialog ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest B. The Little Match Girl(贪心)
传送门 Description Using at most 7 matchsticks, you can draw any of the 10 digits as in the following p ...
- 第二轮冲刺-Runner站立会议05
今天:将baseadapter的原理弄清楚了 明天:解决适配问题 困难:程序会停止运行
- linux中ldconfig的使用介绍
linux中ldconfig的使用介绍 ldconfig是一个动态链接库管理命令,其目的为了让动态链接库为系统所共享. ldconfig的主要用途: 默认搜寻/lilb和/usr/lib,以及配置文件 ...