题目链接:http://codeforces.com/contest/465/problem/C

题意:给出一个不存在2个或以上回文子串的字符串,全是由小写字母组成而且字母下表小于p,问刚好比这个字符串

大的字符串是什么,如果没有输出NO

题解:就是遍历一遍当前字母要么不变要么增大,如果增大自行构成后续最小。如果等于继续遍历。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char s[1010];
int a[1010] , c[1010][1010];
int n , p;
int main() {
scanf("%d%d" , &n , &p);
scanf("%s" , s + 1);
for(int i = 1 ; i <= n ; i++) {
a[i] = s[i] - 'a';
}
a[0] = -1;
memset(c , -1 , sizeof(c));
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j < i ; j++) {
c[i][j] = a[j];
}
for(int j = a[i] + 1 ; j < p ; j++) {
if(i == 1) {
c[i][i] = j;
break;
}
else {
if(j != a[i - 1] && j != a[i - 2]) {
c[i][i] = j;
break;
}
}
}
for(int j = i + 1 ; j <= n ; j++) {
for(int k = 0 ; k < p ; k++) {
if(k != c[i][j - 1] && k != c[i][j - 2]) {
c[i][j] = k;
break;
}
}
}
}
int flag = 1 , temp = 0;
for(int i = n ; i >= 1 ; i--) {
flag = 0;
temp = i;
for(int j = 1 ; j <= n ; j++) {
if(c[i][j] == -1) {
flag = 1;
break;
}
}
if(!flag) break;
}
if(!flag) {
for(int i = 1 ; i <= n ; i++) {
char cp = c[temp][i] + 'a';
printf("%c" , cp);
}
printf("\n");
}
else {
printf("NO\n");
}
return 0;
}

codeforces 465 C. No to Palindromes!(暴力+思维)的更多相关文章

  1. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  2. Codeforces Round #315 (Div. 1) A. Primes or Palindromes? 暴力

    A. Primes or Palindromes?Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3261 ...

  3. Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 暴力

    C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...

  4. Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】

    A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  5. codeforces 361 C. Levko and Array Recovery(暴力+思维)

    题目链接:http://codeforces.com/contest/361/problem/C 题意:对一个数列有这么两个操作 1.(1,l,r,p)..将区间[l,r]所有数都加上p 2.(2,l ...

  6. Codeforces Round #580 (Div. 2)D(思维,Floyd暴力最小环)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;const int maxn=300;cons ...

  7. CodeForces - 1228D (暴力+思维+乱搞)

    题意 https://vjudge.net/problem/CodeForces-1228D 有一个n个顶点m条边的无向图,在一对顶点中最多有一条边. 设v1,v2是两个不相交的非空子集,当满足以下条 ...

  8. Yet Another Array Queries Problem CodeForces - 863D (暴力/思维)

    You are given an array a of size n, and q queries to it. There are queries of two types: 1 li ri — p ...

  9. Codeforces Round #588 (Div. 2)C(思维,暴力)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int a[27],b[27];int vis ...

随机推荐

  1. poj 3714 寻找最近点对

    参考自<编程之美>169页,大概原理就是把区间分成两部分,然后递归找每一部分中最近的点对,还有一种情况就是这个点对分属于这两部分,然后选两部分中的部分点枚举即可,取其最小值. //2013 ...

  2. spring实战学习笔记(一)spring装配bean

    最近在学习spring boot 发现对某些注解不是很深入的了解.看技术书给出的实例 会很疑惑为什么要用这个注解? 这个注解的作用?有其他相同作用的注解吗?这个注解的运行机制是什么?等等 spring ...

  3. Pyenv虚拟环境的创建(虚拟机)

    创建pyenv虚拟环境 sudo yum install openssl* 安装其所需要的库文件 git clone https://github.com/yyuu/pyenv.git ~/.pyen ...

  4. Flink 从0到1学习 —— Flink 中如何管理配置?

    前言 如果你了解 Apache Flink 的话,那么你应该熟悉该如何像 Flink 发送数据或者如何从 Flink 获取数据.但是在某些情况下,我们需要将配置数据发送到 Flink 集群并从中接收一 ...

  5. Linux基础进程管理优先级

    一.进程优先级 Linux进程调度及多任务 每个cpu(或者cpu核心)在一个时间点上只能处理一个进程,通过时间片技术,Linux实际能够运行的进程(和线程数)可以超出实际可用的cpu及核心数量.Li ...

  6. ASP.NET CORE系列【七】分析NetCore启动原理

    前言 有很久一段时间没更新了,因为工作和家里的问题导致没能坚持, 现在开始会继续每周更新,主要是记录自己所学和一起讨论解决过的问题,一起成长, 为.net圈子添砖加瓦! 介绍 到目前为止应该很多同学已 ...

  7. java学习-NIO(二)Buffer

    当我们需要与 NIO Channel 进行交互时, 我们就需要使用到 NIO Buffer, 即数据从 Buffer读取到 Channel 中, 并且从 Channel 中写入到 Buffer 中.缓 ...

  8. python3 how to creat alphabet

    Python: How To Generate a List Of Letters In The Alphabet  Method 1# First we need to figure out the ...

  9. linux细节操作的

    一>安装mysql 可以直接在linux系统下载 下载之前要安装wget插件 下载命令 wget 后面跟安装软件的url 比如mysql wget http://repo.mysql.com/m ...

  10. 一份程序猿单词列表(updating)

    以下单词是个人平时阅读英文文档时遇到的一些“生”单词,该文档将持续更新,可以持续关注https://github.com/hylinux1024/word-list-for-programmer hi ...