题意:给定一个字符,让你用前 k 个字符把它排成 n 长度,相邻的字符不能相等,并且把字典序最小。

析:其实很简单么,我们只要多循环ab,就行,最后再把剩下的放上,要注意k为1的时候。

代码如下:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int maxn = 10000 + 5;
const int INF = 0x3f3f3f3f;
const int dr[] = {0, 0, 1, -1};
const int dc[] = {1, -1, 0, 0};
int a[maxn];
vector<int> ans; int main(){
int n, m, d, k;
scanf("%d %d", &n, &k);
if(n < k){
printf("-1\n");
return 0;
}
if(k == 1){
if(n > 1){
printf("-1\n");
}
else printf("a");
return 0;
}
for(int i = 0; i < n-k+2; ++i){
if(i % 2) ans.push_back(1);
else ans.push_back(0);
}
for(int i = n-k+2; i < n; ++i)
ans.push_back(i-n+k);
for(int i = 0; i < n; ++i)
printf("%c", ans[i] + 'a');
return 0;
}

CodeForces 288A Polo the Penguin and Strings (水题)的更多相关文章

  1. CodeForces 289A Polo the Penguin and Segments (水题)

    题意:给你 n 段区间,而且还是不相交的,然后你只能向左扩展左端点,或者向右扩展右端点,然后扩展最少的步数让整数总数能够整除 k. 析:很简单么,只要在记录算一下数量,然后再算出 k 的倍数差多少就行 ...

  2. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  3. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  4. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  5. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  6. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  7. Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

    对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...

  8. codeforces 288A:Polo the Penguin and Strings

    Description Little penguin Polo adores strings. But most of all he adores strings of length n. One d ...

  9. A. Polo the Penguin and Strings

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. DjangoORM执行原生sql

    在Django中使用原生Sql主要有以下几种方式: 一:extra:结果集修改器,一种提供额外查询参数的机制 二:raw:执行原始sql并返回模型实例 三:直接执行自定义Sql   这种方式完全不依赖 ...

  2. kubernetes 学习 常用命令

    1  kubectl get nodes      #查看nodes节点情况 2  kubectl describe  node node_name_XXXX           # 查看nodes详 ...

  3. 利用百度API(JavaScript 版)实现在地图上绘制任一多边形,并判断给定经纬度是否在多边形范围内。以及两点间的测距功能

    权声明:本文为博主原创文章,未经博主允许不得转载. 利用百度API(JavaScript 版)实现在地图上绘制任一多边形,并判断给定经纬度是否在多边形范围内.以及两点间的测距功能. 绘制多边形(蓝色) ...

  4. Python极其简单的分布式异步作业管理系统RQ入门

    Python极其简单的分布式异步作业管理系统RQ入门 原创 2017-08-19 lixing 生信人 Python极其简单的分布式异步作业管理系统RQ入门 1. 什么是Job? Job直译过来就是工 ...

  5. python查找文件相同的和包含汉字的

    #!/usr/bin/env python # Version = 3.5.2 import os import time d_path = '/data/media' log_file = 'res ...

  6. 左侧倒换菜单 frameset 已过时

    <!doctype html><html><frameset cols="200,*"> <frame src="left.ht ...

  7. ffmpeg源码分析三:transcode_init函数 (转3)

    原帖地址:http://blog.csdn.net/austinblog/article/details/25061945 transcode_init()函数是在转换前做准备工作的.下面看看其源代码 ...

  8. C++Primer笔记-----day01

    =======================================================day01======================================== ...

  9. 【303】C# 复制窗体 & 修改名称

    参考:C#复制粘贴窗体 参考:VS修改项目解决方案名称 一.复制窗体 在“解决方案资源管理器”(以下简称:管理器)中选择要复制的窗体,比如要复制Form2,则在Form2.cs上右单击,选择复制. 在 ...

  10. iOS常用动画 类封装

    //这是一个很好的动画封装类 很容易明白很详细 和大家分享 // CoreAnimationEffect.h // CoreAnimationEffect // // Created by Vince ...