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 ...
随机推荐
- 第七章 HTTP流量管理(二) URL 重写
URL 重定向功能: 浏览器中输入 http://<host_name>:31380/v1/service-A/XXXX 经过下面的重定向,实际调用的是serviceA的/v1/XXXX ...
- IDA Pro 权威指南学习笔记(十) - 栈帧
栈帧(stack frame)是在程序的运行时栈中分配的内存块,用于特定的函数调用 如果一个函数没有执行则不需要内存,当函数被调用时就需要用到内存 1.传给函数的参数的值需要存储到函数能够找到它们的位 ...
- Mysql Docker Container Command
Hello, in my docker-compose file I have the following: db: image: mysql command: mysqld --character- ...
- java后台面试题整理
java基础 Arrays.sort实现原理和Collection实现原理foreach和while的区别(编译之后)线程池的种类,区别和使用场景分析线程池的实现原理和线程的调度过程线程池如何调优线程 ...
- 深入浅出 Java Concurrency (12): 锁机制 part 7 信号量(Semaphore)
Semaphore 是一个计数信号量.从概念上讲,信号量维护了一个许可集.如有必要,在许可可用前会阻塞每一个 acquire(),然后再获取该许可.每个 release() 添加一个许可,从而可能 ...
- 巧用setTimeout函数设置程序后门
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- css伪类(Pseudo-classes)
简介:伪类(Pseudo classes)是选择符的螺栓,用来指定一个或者与其相关的选择符的状态.它们的形式是selector:pseudo class { property: value; },简单 ...
- keil中结构体跨文件调用
在a.h中: 定义了, struct ABC{ short a; short b; ```}; 在a.c中(#include "a.h"): 声明了, struct ABC stc ...
- TCP的交互数据流
在TCP进行数据传输时,可以分为成块数据流和交互数据流两种,如果按字节计算,成块数据与交互数据的比例约为90%和10%,TCP需要同时处理这两类数据,且处理的算法不同. 书籍本章中以Rlogin应用为 ...
- XNA数学库
XNA Math Vectors 在direct3D 9 和10中,包含3D数学库的D3DX库支持向量和其他核心类型的计算.在direct11中,D3DX库不在包含3D数学库,取而代之的是XNA数学库 ...