CodeForces 288A Polo the Penguin and Strings (水题)
题意:给定一个字符,让你用前 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 (水题)的更多相关文章
- CodeForces 289A Polo the Penguin and Segments (水题)
题意:给你 n 段区间,而且还是不相交的,然后你只能向左扩展左端点,或者向右扩展右端点,然后扩展最少的步数让整数总数能够整除 k. 析:很简单么,只要在记录算一下数量,然后再算出 k 的倍数差多少就行 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- Codeforces Round #190 (Div. 2) 水果俩水题
后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...
- Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告
对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...
- 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 ...
- A. Polo the Penguin and Strings
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
随机推荐
- Converter(转换器)与Formatter(格式化) ,Validator(验证器)
Converter(转换器)与Formatter(格式化)都可以用于将一种对象类型转换为另一种对象类型.Converter是通用元件,可以在应用程序的任意层中使用,而Fotermatter这是专门为W ...
- c++ 搜索二叉树 插入,删除,遍历操作
搜索二叉树是一种具有良好排序和查找性能的二叉树数据结构,包括多种操作,本篇只介绍插入,排序(遍历),和删除操作,重点是删除操作比较复杂,用到的例子也是本人亲自画的 用到的测试图数据例子 第一.构建节点 ...
- Hashtable、HashMap
JDK1.6 API public class Hashtable<K,V>extends Dictionary<K,V>implements Map<K,V>, ...
- file_get_content服务器对服务器二进制文件上传
1.file_get_contents函数可安全用于二进制对象,适用服务器对服务器文件是上传场景 base64_encode(file_get_contents('1268879774AaCl4wIE ...
- mysql 随机查询 记录集
有时候需求需要随机从数据库查询若干条记录集,网上搜了一下,几篇博文都是些重复的.....不知道他们谁抄的谁的,这里除了介绍提供一种笔者自己想到的方法,本质都是利用mysql 的rand() 第一种方法 ...
- jaegeropentracing的Java-client完整分布式追踪链
jaegeropentracing的Java-client完整分布式追踪链,在分布式系统中透传trace信息 之前文章记录了jaegeropentracing的Java-client追踪链在单系统中的 ...
- Sass 入门 (一) 安装Sass
Sass安装 ruby安装 因为sass依赖于ruby环境,所以装sass之前先确认装了ruby.先导官网下载个ruby 在安装的时候,请勾选Add Ruby executables to your ...
- Expect 小脚本
简介: Expect 可以替系统管理员完成与系统的交互式操作 shell > yum -y install expect # 可以通过 yum 安装 shell > which expec ...
- select sum也会返回null值
SELECT SUM(detail.VAL) FROM AI_SDP_ORDER_MONTH_DETAIL_201706 detail 如果所有的VAL都是null的话,或者根本就不存在 ...
- knockout的监控数组实现
knockout应该是博客园群体中使用最广的MVVM框架,但鲜有介绍其监控数组的实现.最近试图升级avalon的监控数组,决定好好研究它一番,看有没有可借鉴之处. ko.observableArray ...