题目链接: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. Java1.8新特性实战

    public class JDK8_features {private ArrayList<Integer> list; @Testpublic void test(){/*** 1.La ...

  2. RocketMQ中Broker的消息存储源码分析

    Broker和前面分析过的NameServer类似,需要在Pipeline责任链上通过NettyServerHandler来处理消息 [RocketMQ中NameServer的启动源码分析] 实际上就 ...

  3. solidity智能合约字节数最大值及缩减字节数

    智能合约最大字节数 在Solidity中,EIP 170将contract的最大大小限制为24 KB .因此,如果智能合约内容过多,会导致无法进行发布操作. 减少压缩字节数方法 方法及变量命名 在一定 ...

  4. AQS之CountDownLatch、Semaphore、CyclicBarrier

    CountDownLatch A synchronization aid that allows one or more threads to wait until a set of operatio ...

  5. Java 通过反射改变私有变量的值

    直接上代码 import java.lang.reflect.Field; public class Main {      public static void main(String[] args ...

  6. 干货 |《从Lucene到Elasticsearch全文检索实战》拆解实践

    1.题记 2018年3月初,萌生了一个想法:对Elasticsearch相关的技术书籍做拆解阅读,该想法源自非计算机领域红火已久的[樊登读书会].得到的每天听本书.XX拆书帮等. 目前市面上Elast ...

  7. ecshop 管理后台菜单及权限管理机制

    ecshop 所有的一级菜单选项存放于languages\zh_cn\admin\common.php 文件里面,使用 $_LANG['02_cat_and_goods'] = '商品管理';  这样 ...

  8. BFS-迷宫问题

    问题描述 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, ...

  9. 小白学Python(3)——输入和输出,显示你的名字

    任何计算机程序都是为了执行一个特定的任务,有了输入,用户才能告诉计算机程序所需的信息,有了输出,程序运行后才能告诉用户任务的结果. 输入是Input,输出是Output,因此,我们把输入输出统称为In ...

  10. .netcore consul实现服务注册与发现-集群部署

    一.Consul的集群介绍 Consul Agent有两种运行模式:Server和Client.这里的Server和Client只是Consul集群层面的区分,与搭建在Cluster之上的应用服务无关 ...