题意:给定一个字符,让你用前 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. soap,socket

    Socket 接口是访问 Internet 使用得最广泛的方法. 如果你有一台刚配好TCP/IP协议的主机,其IP地址是202.120.127.201, 此时在另一台主机或同一台主机上执行ftp 20 ...

  2. 仅用CSS3创建h5预加载雷达圈

    <head> <meta charset="UTF-8"> <title></title> <style type=" ...

  3. <转>Python3.x和Python2.x的区别

    这个星期开始学习Python了,因为看的书都是基于Python2.x,而且我安装的是Python3.1,所以书上写的地方好多都不适用于Python3.1,特意在Google上search了一下3.x和 ...

  4. 表格字段常用注解@NotBlank @NotEmpty @NotNul @Pattern

    在Hibernate Validator(org.hibernate.validator.constraints)中: @NotEmpty://CharSequence, Collection, Ma ...

  5. 跟我一起学kafka(二)

    kafka安装到linux服务器中的情况较多,但是我们现在在学习当中,所以可以拿windows先试试手.要想学kafk那么必然要做一件事就是安装好kafka,下面我讲详细得windows下安装kafk ...

  6. 推荐一篇mysql优化干货

    淘宝的技术一直比较前沿,特别是LVS的作者加入淘宝后,淘宝和阿里的开源做的有声有色,君不见淘宝出了tengine,tairs,tddl,hsf(soa框架,未开源),tfs(小文件存储系统)等等,阿里 ...

  7. 用CSS制作小三角提示符号

    今天在项目中遇到了如下图的切图要求. 对,重点就是那个小三角提示符号. html 结构如下 <div class="wrap"> <div class=" ...

  8. 9.redis安全

    转自:http://www.runoob.com/redis/redis-tutorial.html Redis 安全 我们可以通过 redis 的配置文件设置密码参数,这样客户端连接到 redis ...

  9. 控件的WndProc WindowProc

    SubClassWndProc This example shows how to use the WndProc method and the WindowProc property to subc ...

  10. Android真机调试手动添加程序包的LogCat

    android真机调试有时候看LogCat 时,有时候那个跑的本程序的LogCat 没有出现而是 出现的是" All messages (no filters) " .此时 的Lo ...