G.Longest Palindrome Substring
链接: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.
思路:
找类似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的更多相关文章
- 5.Longest Palindrome substring
/* * 5.Longest Palindrome substring * 2016-4-9 by Mingyang 自然而然的想到用dp来做 * 刚开始自己做的时候分的条件太细,两个index相等, ...
- [LeetCode] Longest Palindrome Substring 具体分析
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- 【算法】最长回文子串 longest palindrome substring
对于字符串S, 要找到它最长的回文子串,能想到的最暴力方法,应该是对于每个元素i-th都向左向右对称搜索,最后用一个数组span 记录下相对应元素i-th为中心的回文子串长度. 那么问题来了: 1. ...
- LeetCode the longest palindrome substring
回文检测,参考http://blog.csdn.net/feliciafay/article/details/16984031 使用时间复杂度和空间复杂度相对较低的动态规划法来检测,具体的做法 图一 ...
- 最长回文字串 (The longest palindrome substring)
这两天去学了一下,觉得下面那篇文章写的很好,有例子,比较容易懂,所以转一下. 以下内容来自:hihoCoder: 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互 ...
- Leetcode: Longest Palindromic Substring && Summary: Palindrome
Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...
- 转载-----Java Longest Palindromic Substring(最长回文字符串)
转载地址:https://www.cnblogs.com/clnchanpin/p/6880322.html 假设一个字符串从左向右写和从右向左写是一样的,这种字符串就叫做palindromic st ...
- leetcode--5 Longest Palindromic Substring
1. 题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximu ...
- Java Longest Palindromic Substring(最长回文字符串)
假设一个字符串从左向右写和从右向左写是一样的,这种字符串就叫做palindromic string.如aba,或者abba.本题是这种,给定输入一个字符串.要求输出一个子串,使得子串是最长的padro ...
随机推荐
- npm使用淘宝镜像安装包
npm使用registry这个属性指定仓库,因此配置这个属性即可.修改npm配置属性的几种方法详见官方文档. 这里只贴出修改registry的方法,以下三种任意一种即可: 修改~/.npmrc文件(没 ...
- Mysql中文检索匹配与正则
今天在用sql模糊查询包含字母d的时候,发现一些不包含此字母的也被查询出来了: SELECT * FROM custom WHERE custom_realname LIKE '%d%' 查询了一下, ...
- tensorflow kmeans 聚类
iris: # -*- coding: utf-8 -*- # K-means with TensorFlow #---------------------------------- # # This ...
- sphinx 全文搜索引擎
sphinx的安装与配置 --------------------------------------------------------------------------------------- ...
- Linux MySQL5.5的安装
1.安装cmake [root@server1 src]# cd /opt/ipnms/src[root@server1 src]# tar zxvf cmake-2.8.4.tar.gz[root@ ...
- .NETFramework-Web.Services:WebMethodAttribute
ylbtech-.NETFramework-Web.Services:WebMethodAttribute 1.程序集 System.Web.Services, Version=4.0.0.0, Cu ...
- c# link 学习网站
http://www.cnblogs.com/shanyou/p/4353433.html
- Process打开文件
引用:using System.Diagnostics; 打开文件夹: System.Diagnostics.Process.Start(FilePath); 打开文件夹中某个文件: System.D ...
- 转:在Linux上安装ant环境
1.从http://ant.apache.org 上下载tar.gz版ant 2.复制到/usr下 3.tar -vxzf apahce-ant-1.9.2-bin.tar.gz 解压 4.chow ...
- day1 java基础回顾-Junit单元测试
Junit单元测试框架的基本使用 一.搭建环境: 导入junit.jar包(junit4) 二.写测试类: 0,一般一个类对应一个测试类. 1,测试类与被测试类最好是放到同一个包中(可以是不同的源文件 ...