链接: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. C/C++连接查询MYSQL

    1. [代码][C/C++]代码 #include <mysql/mysql.h>#include <stdio.h>#include <string.h>int ...

  2. BZOJ 1651 [Usaco2006 Feb]Stall Reservations 专用牛棚:优先队列【线段最大重叠层数】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1651 题意: 给你n个线段[a,b],问你这些线段重叠最多的地方有几层. 题解: 先将线段 ...

  3. [acm]HDOJ 3082 Simplify The Circuit

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3082 字符串处理+并联电阻公式 //11481261 2014-08-18 16:52:47 Acc ...

  4. P1912 [NOI2009]诗人小G[决策单调性优化]

    地址 n个数划分若干段,给定$L$,$p$,每段代价为$|sum_i-sum_j-1-L|^p$,求总代价最小. 正常的dp决策单调性优化题目.不知道为什么luogu给了个黑题难度.$f[i]$表示最 ...

  5. Linux User

    1.用户的工作目录,在/etc/passwd中查看 2.如果shell=bin/false(正常为bin/bash)代表禁止登录,这样就无法登录以及通过su进行切换: 3.修改,usermod -d ...

  6. Adobe Flash Player 27 on Fedora 27/26, CentOS/RHEL 7.4/6.9

    This is guide, howto install Adobe Flash Player Plugin version 27 (32-bit and 64-bit) with YUM/DNF o ...

  7. JVM中的Hello World运行机制:

    栗子: package zagoo; public class HelloWorld { public static String HELLOWORLD="Hello World" ...

  8. fgets(),fscanf()的输入测试与FILE中的当前指针

    fgets(string,int,fp) 回车读入测试 #include <stdio.h> int main() { FILE *fp; ],ch2[],ch3[],ch4[]; fp= ...

  9. 第一课、OpenGL绘制直线等等

    第一课.OpenGL绘制直线等等 分类: [开发技术]OpenGL 2012-01-18 14:59 5217人阅读 评论(0) 收藏 举报 buffer图形c // //  main.c //  o ...

  10. 2017年第八届蓝桥杯国赛试题(JavaA组)

    1.结果填空 (满分19分)2.结果填空 (满分47分)3.代码填空 (满分21分)4.程序设计(满分35分)5.程序设计(满分79分)6.程序设计(满分99分) 1.标题:图书排列 将编号为1~10 ...