http://codeforces.com/contest/465/problem/C

题意:给你一个字符串,然后按照字典序找出下一个字符串,这个字符串中不能含有长度大于等于2的子串为回文串,如果含有输出,否则输出NO;

思路:判断回文串时只需判断要修改的i位置,i+1位置和i+2位置是不是与这个要修改的字符相等。字符串的前缀不含有回文子字符串,改变i位后也不会含有。

 #include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
#define maxn 1000010
#define ll long long
using namespace std;
const int inf=<<; int n,p;
char str[maxn];
char s1[maxn]; int main()
{
scanf("%d%d",&n,&p);
scanf("%s",str);
strcpy(s1,str);
bool flag=false;
for(int i=n-; i>=; i--)
{
for(int j=(str[i]-'a')+; j<p; j++)
{
char ch='a'+j;
if(str[max(i-,)]==ch||str[max(i-,)]==ch)
{
continue;
}
str[i]=ch;
flag=true;
break;
}
if(flag)
{
for(int j=i+; j<n; j++)
{
for(int k=; k<p; k++)
{
if((j->=&&str[j-]=='a'+k)||(j->=&&str[j-]=='a'+k))
{
continue;
}
str[j]='a'+k;
break;
}
}
if(strcmp(s1,str)!=)
{
printf("%s\n",str);
return ;
}
}
}
printf("NO\n");
return ;
}

codeforces C. No to Palindromes!的更多相关文章

  1. Codeforces 570E - Pig and Palindromes - [滚动优化DP]

    题目链接:https://codeforces.com/problemset/problem/570/E 题意: 给出 $n \times m$ 的网格,每一格上有一个小写字母,现在从 $(1,1)$ ...

  2. 【CodeForces】914 E. Palindromes in a Tree 点分治

    [题目]E. Palindromes in a Tree [题意]给定一棵树,每个点都有一个a~t的字符,一条路径回文定义为路径上的字符存在一个排列构成回文串,求经过每个点的回文路径数.n<=2 ...

  3. codeforces 465C.No to Palindromes! 解题报告

    题目链接:http://codeforces.com/problemset/problem/464/A 题目意思:给出一个长度为 n 且是 tolerable 的字符串s,需要求出字典序最小的长度也为 ...

  4. codeforces 688B B. Lovely Palindromes(水题)

    题目链接: B. Lovely Palindromes time limit per test 1 second memory limit per test 256 megabytes input s ...

  5. codeforces 568a//Primes or Palindromes?// Codeforces Round #315 (Div. 1)

    题意:求使pi(n)*q<=rub(n)*p成立的最大的n. 先收集所有的质数和回文数.质数好搜集.回文数奇回文就0-9的数字,然后在头尾添加一个数.在x前后加a,就是x*10+a+a*pow( ...

  6. dp --- Codeforces 245H :Queries for Number of Palindromes

    Queries for Number of Palindromes Problem's Link:   http://codeforces.com/problemset/problem/245/H M ...

  7. Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题

    B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...

  8. Educational Codeforces Round 75 (Rated for Div. 2) B. Binary Palindromes

    链接: https://codeforces.com/contest/1251/problem/B 题意: A palindrome is a string t which reads the sam ...

  9. CodeForces 1251B --- Binary Palindromes

    [CodeForces 1251B --- Binary Palindromes] Description A palindrome is a string t which reads the sam ...

随机推荐

  1. 字符串匹配算法-BM

    在用于查找子字符串的算法中,BM(Boyer-Moore)算法是当前有效且应用比较广泛的一种算法,各种文本编辑器的“查找”功能(Ctrl+F),大多采用Boyer-Moore算法.比我们学习的KMP算 ...

  2. 【转】cocos2d-x学习笔记03:绘制基本图元

    第一部分:基本图形绘制 cocos2dx封装了大量opengl函数,用于快速绘制基本图形,这些代码的例子在,tests\DrawPrimitivesTest目录下 注意,该方法是重载node的draw ...

  3. Android开发之View重写相关API-onLayout,onMeasure,MeasureSpec

     1.onLayout android.view.ViewGroup protected void onLayout(boolean changed, int l, int t, int r, int ...

  4. Silverlight OOB 程序自动更新

    Silverlight OOB 程序 提供了非常方便的自动更新功能! 要让 Silverlight OOB 安装到客户端电脑后实现自动更新,必须实现以下两个条件: 一.为 程序的 xap  文件进行签 ...

  5. Installing the .NET Framework 4.5, 4.5.1

    This article provides links for installing the .NET Framework 4.5 and 4.5.1 on your computer.  If yo ...

  6. Tomcat 的 SSL 配置

    本教程使用 JDK 6 和 Tomcat 7,其他版本类似. 基本步骤: 使用 java 创建一个 keystore 文件 配置 Tomcat 以使用该 keystore 文件 测试 配置应用以便使用 ...

  7. HDU-1037(水水水题)

    Keep on Truckin' Problem Description Boudreaux and Thibodeaux are on the road again . . . "Boud ...

  8. 黑马程序员- IO(Input- Output)(一)

    ------Java培训.Android培训.iOS培训..Net培训.期待与您交流! ------- API包: Java.io.* 缘来: java通过操作数据对象是通过流的方式来创建的 作用: ...

  9. Android - 折线图

    使用Android的canvas,画折线图:代码为: package spt.view; import android.annotation.SuppressLint; import android. ...

  10. DataGridView 绑定 List

    DataGridView 绑定 List<T> 不会自动更新 正确方式是将  List<T> 设置为 BindingList<T> 即可 (双向绑定)