链接:https://ac.nowcoder.com/acm/contest/908/G

题意:

A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. For example, ”a”、”aba”、“abba” are palindrome and “abc”、”aabb” are not.

Let’s define a new function f(s).

For some string s, f(s) is the length of the longest palindrome substring.

    Now you should decide for the given string s, whether f(s) is great than 1.
    The string s only contains lowercase letters.

思路:

找类似aa, aba这种的回文串就行了

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t; int main()
{
cin >> n;
string s;
cin >> s;
bool flag = false;
for (int i = 1;i < n-1;i++)
{
if (s[i] == s[i-1] || s[i-1] == s[i+1])
{
flag = true;
break;
}
}
if (s[n-1] == s[n-2])
flag = true;
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl; return 0;
}

  

G.Longest Palindrome Substring的更多相关文章

  1. 5.Longest Palindrome substring

    /* * 5.Longest Palindrome substring * 2016-4-9 by Mingyang 自然而然的想到用dp来做 * 刚开始自己做的时候分的条件太细,两个index相等, ...

  2. [LeetCode] Longest Palindrome Substring 具体分析

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  3. 【算法】最长回文子串 longest palindrome substring

    对于字符串S, 要找到它最长的回文子串,能想到的最暴力方法,应该是对于每个元素i-th都向左向右对称搜索,最后用一个数组span 记录下相对应元素i-th为中心的回文子串长度. 那么问题来了: 1. ...

  4. LeetCode the longest palindrome substring

    回文检测,参考http://blog.csdn.net/feliciafay/article/details/16984031 使用时间复杂度和空间复杂度相对较低的动态规划法来检测,具体的做法 图一 ...

  5. 最长回文字串 (The longest palindrome substring)

    这两天去学了一下,觉得下面那篇文章写的很好,有例子,比较容易懂,所以转一下. 以下内容来自:hihoCoder: 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互 ...

  6. Leetcode: Longest Palindromic Substring && Summary: Palindrome

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

  7. 转载-----Java Longest Palindromic Substring(最长回文字符串)

    转载地址:https://www.cnblogs.com/clnchanpin/p/6880322.html 假设一个字符串从左向右写和从右向左写是一样的,这种字符串就叫做palindromic st ...

  8. leetcode--5 Longest Palindromic Substring

    1. 题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximu ...

  9. Java Longest Palindromic Substring(最长回文字符串)

    假设一个字符串从左向右写和从右向左写是一样的,这种字符串就叫做palindromic string.如aba,或者abba.本题是这种,给定输入一个字符串.要求输出一个子串,使得子串是最长的padro ...

随机推荐

  1. ZOJ 3640 Help Me Escape:期望dp

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3640 题意: 有一个吸血鬼被困住了,他要逃跑... 他面前有n条 ...

  2. Ajax不能接受php return值的原因

    PHP在处理ajax返回值的时候,如果使用return如 return $result会失败,echo $result却没问题.解释原因如下: 1.ajax请求从服务器端读取返回值,而且这些返回值必须 ...

  3. html5--2.1新的布局元素(1)-header/footer

    html5--2.1新的布局元素(1)-header/footer 学习要点 了解header/footer的语义和用法 使用header/footer进行一个简单的布局 header元素(标签) 用 ...

  4. 多线程mtr-代码

    #!/bin/env python # -*- coding: utf-8 -*- # @Date : 2015-09-06 11:30:48 # @Author : Your Name (you@e ...

  5. bootstrap框架日期时间 开始日期和结束日期选择

    页面表单查询时,常要求要查询一个日期时间段内的数据,若采用bootstrap框架的datetimepicker插件来控制,需要了解怎么个用法:

  6. 一个节点rac+单节点dg网络配置(listener.ora与tnsnames.ora)

    环境说明:  实验环境是 一个节点的 rac + 单机dg    (主备全部用asm存储) tnsnames.ora  文件  (oracle用户) node 1 : node1-> pwd / ...

  7. 百度地图API的第一次接触——热区

    1.代码很简单 var map = new BMap.Map("container"); var point = new BMap.Point(116.404, 39.915); ...

  8. POJ2186(有向图缩点)

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28379   Accepted: 11488 De ...

  9. JavaScript:非输入框禁用退格键

    在js文件或<javascript>标签中加入如下代码: /** *非输入框禁用退格键 */ function banBackspace(e) { var ev = e || window ...

  10. 系统启动挂载根文件系统时Kernel panic

    转自:http://qiuye.iteye.com/blog/543595 这类问题很常见,先总体介绍一下解决思路. 能出现让人激动的的控制台,那么系统移植已经接近完成:但是不少人在最后一步出现问题. ...