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 ...
随机推荐
- Java程序中不通过hadoop jar的方式访问hdfs
一般情况下,我们使用Java访问hadoop distributed file system(hdfs)使用hadoop的相应api,添加以下的pom.xml依赖(这里以hadoop2.2.0版本 ...
- kubernetes 学习 service相关
1: service有什么用? 直接通过Pod的IP地址和端口号可以访问容器应用,但是pod的IP地址是不可靠的,比如POD出现故障后,有可能在另外一个NOde上启动,这样Pod的IP ...
- DynamicConverter
folly/DynamicConverter.h When dynamic objects contain data of a known type, it is sometimes useful t ...
- 生成短的uuid
package test1; import java.util.Random; import java.util.UUID; public class ShareCodeUtil { private ...
- START WITH...CONNECT BY PRIOR详解
START WITH...CONNECT BY PRIOR详解 START WITH...CONNECT BY PRIOR详解 ORACLE中的SELECT语句可以用START WITH...CONN ...
- MessageBox 函数
函数原型: int WINAPI MessageBox( _In_opt_ HWND hWnd, _In_opt_ LPCTSTR lpText, _In_opt_ LPCTSTR lpCaption ...
- 第一章 : Android Studio 介绍 [Learn Android Studio 汉化教程]
摘自:http://ask.android-studio.org/?/question/789,为便于学习重新整理.. 本章将引导您完成安装和设置开发环境,然后你就可以跟随本书的例子和课程学习. 首先 ...
- 关于java中word转html
http://www.dewen.org/q/5820/java%E4%B8%AD%E6%80%8E%E4%B9%88%E5%B0%86word%E6%96%87%E6%A1%A3%E8%BD%ACh ...
- python开发最受欢迎的十款工具
python开发最受欢迎的十款工具 dreamyla3个月前 今天小编给正在学习python开发的朋友介绍十款最受欢迎的开发工具,因为在学习python开发过程中少不了IDE或者代码编辑器,想要提高开 ...
- URLDownloadToFileW
[ilink32 Error] Error: Unresolved external 'URLDownloadToFileW' referenced from D:\USERS\PUBLIC\DOCU ...