codeforces C. No to Palindromes!
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!的更多相关文章
- Codeforces 570E - Pig and Palindromes - [滚动优化DP]
题目链接:https://codeforces.com/problemset/problem/570/E 题意: 给出 $n \times m$ 的网格,每一格上有一个小写字母,现在从 $(1,1)$ ...
- 【CodeForces】914 E. Palindromes in a Tree 点分治
[题目]E. Palindromes in a Tree [题意]给定一棵树,每个点都有一个a~t的字符,一条路径回文定义为路径上的字符存在一个排列构成回文串,求经过每个点的回文路径数.n<=2 ...
- codeforces 465C.No to Palindromes! 解题报告
题目链接:http://codeforces.com/problemset/problem/464/A 题目意思:给出一个长度为 n 且是 tolerable 的字符串s,需要求出字典序最小的长度也为 ...
- codeforces 688B B. Lovely Palindromes(水题)
题目链接: B. Lovely Palindromes time limit per test 1 second memory limit per test 256 megabytes input s ...
- 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( ...
- dp --- Codeforces 245H :Queries for Number of Palindromes
Queries for Number of Palindromes Problem's Link: http://codeforces.com/problemset/problem/245/H M ...
- Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题
B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...
- 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 ...
- CodeForces 1251B --- Binary Palindromes
[CodeForces 1251B --- Binary Palindromes] Description A palindrome is a string t which reads the sam ...
随机推荐
- OpenJDK和Sun/OracleJDK 区别 与联系
首先要先明确之间,以及OpenJDK 6.OpenJDK 7.OpenJDK 7u和OpenJDK 8等项目之间是什么关系,这有助于确定接下来编译要使用的JDK版本和源码分支.从前面介绍的Java发展 ...
- Linux I/O Scheduler--CFQ(上)图解
http://blog.csdn.net/vanbreaker/article/details/8299491 http://doc.okbase.net/29060569/archive/46628 ...
- hadoop错误DataXceiver error processing WRITE_BLOCK operation
错误: DataXceiver error processing WRITE_BLOCK operation 原因: 文件操作超租期,实际上就是data stream操作过程中文件被删掉了. ...
- OC学习笔记[注意事项]
alloc new retain之后都必须要调用release方法 计数器要变只有这几种方法 retain release alloc new copy方法才会使计数器改变,谁想用人家对象,就对他 ...
- 汇编语言-[BX]和loop指令
汇编语言-[BX]和loop指令 [BX]指令介绍 mov ax,[bx] 功能: bx为偏移地址,段地址默认为ds.因此,上面指令作用就是将ax中的数据送入内存ds:bx处,即:((ds)*16 + ...
- oracle数据库使用之数据查询入门
1.在查询过程中使用算术表达式对数据进行运算 student表结构如下: 最后一项salary表示每个人的月薪,我现在想查询每个人的年薪: 2.使用nvl函数处理null值,向表中插入一条数据,该数据 ...
- Android(java)学习笔记175:BroadcastReceiver之 外拨电话的广播接收者
首先我们示例工程一览表如下: 1.首先我们还是买一个收音机,定义一个OutCallReceiver继承自BroadcastReceiver,onReceive()方法中定义了监听到广播,要执行的操作: ...
- git 远程追踪
$ git branch --set-upstream-to origin/master http://stackoverflow.com/questions/21729560/how-to-make ...
- Google Map API v2 (三)----- 地图上添加标记(Marker),标记info窗口,即指定经纬度获取地址字符串
接上篇 http://www.cnblogs.com/inkheart0124/p/3536322.html 1,在地图上打个标记 private MarkerOptions mMarkOption; ...
- linux+apache+mod_Jk+tomcat实现tomcat集群
最近一段时间一直在研究实现apache + jk_mod + tomcat实现负载均衡,起初负载均衡算是配置蛮顺利的,但是到了配置tomcat集群时所有配置都没有问题,但是tomcat日志中一直提示没 ...