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. linux 系统调优2

    换作Linux:  1.杀使用内存大,非必要的进程 2.增加连接数 3.磁盘分区的碎片整理 4.服务优化,把不要的服务关闭 5.更换性能更好的硬件,纵向升级 常见优化手段: 1.更换性能更好的硬件,纵 ...

  2. Windows 7系统下局域网文件共享设置方法

    今天给家里增添了一台组装机,小试了一下win7局域网文件共享功能,很爽的说. 记录一下实现方法: 1.关闭防火墙 2.启用共享. 控制面板 – 网络和共享中心 – 更改高级共享设置,将图中的几个选项选 ...

  3. Windows PowerShell:管理服务器

    一.概述 Cmdlets 用于服务器的管理方面主要体现在4个方面:服务.日志.进程.服务器管理器. 1.服务 •  Get-Service.查看某个服务的属性. •  New-Service.创建一个 ...

  4. window和Linux下的软链接

    window下开启软链接命令: mklink /J  "D:\IdeaProjects\bms_work\smartcity_govnet\base_web\target\base_web\ ...

  5. python sklearn.linear_model.LinearRegression.score

    score(self, X, y, sample_weight=None) 作用:返回该次预测的系数R2     其中R2 =(1-u/v).u=((y_true - y_pred) ** 2).su ...

  6. 傻瓜式理解递归之php递归

    写程序这么久了,有时候别人会问道一些算法比如排序啊,递归啊,总是不知道该怎么去说,今天就来整理一下,让更多的人去傻瓜式的理解递归.递归在网络上有很多定义,但有这么一句话听的最多:递归就是自己调用自己! ...

  7. Java对数组对象进行排序

    下面是一组对数组对象进行排序的代码: package com.sun; import java.util.ArrayList; import java.util.Arrays; import java ...

  8. CI框架篇之模型篇--AR操作(2)

    CodeIgniter 和众多的框架一样,有属于自己的一套对数据库的操作方式,本框架更是如此 有属于自己的一套对数据库的安全并且简单的操作, 成为AR操作:下面来对AR操作进行介绍: 首先,确定要启动 ...

  9. MSSQL生成整个数据库的SQL脚本的工具 scptxfr.exe

    scptxfr.exe的路径要正确declare @cMd varchar(1000)set @cmd = 'master.dbo.xp_cmdshell ' + '''c:\"Micros ...

  10. 读取 xml 文件 获取其中保存的数据信息

    建立一个存储过程来返回要读取的数据形成结果集: CREATE PROC dbo.getValuesFromXmlByPath@fileName NVARCHAR(128)asDECLARE @T XM ...