CodeForces Round #527 (Div3) A. Uniform String
http://codeforces.com/contest/1092/problem/A
You are given two integers nn and kk.
Your task is to construct such a string ss of length nn that for each ii from 11 to kk there is at least one ii-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minimal frequency of some letter (the frequency of a letter is the number of occurrences of this letter in a string). If there are several possible answers, you can print any.
You have to answer tt independent queries.
The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — the number of queries.
The next tt lines are contain queries, one per line. The ii-th line contains two integers nini and kiki (1≤ni≤100,1≤ki≤min(ni,26)1≤ni≤100,1≤ki≤min(ni,26)) — the length of the string in the ii-th query and the number of characters in the ii-th query.
Print tt lines. In the ii-th line print the answer to the ii-th query: any string sisi satisfying the conditions in the problem statement with constraints from the ii-th query.
3
7 3
4 4
6 2
cbcacab
abcd
baabab
In the first example query the maximum possible minimal frequency is 22, it can be easily seen that the better answer doesn't exist. Other examples of correct answers: "cbcabba", "ccbbaaa" (any permutation of given answers is also correct).
In the second example query any permutation of first four letters is acceptable (the maximum minimal frequency is 11).
In the third example query any permutation of the given answer is acceptable (the maximum minimal frequency is 33).
代码:
#include <bits/stdc++.h>
using namespace std; int T; int main() {
scanf("%d", &T);
while(T --) {
int N, K;
scanf("%d%d", &N, &K);
string s = "";
if(K > N) {
for(int i = 0; i < N; i ++)
s += ('a' + i);
} else {
int cnt = N / K;
for(int i = 0; i < cnt; i ++) {
for(int j = 0; j < K; j ++)
s += ('a' + j);
} if(N % K) {
N = N - K * cnt;
for(int i = 0; i < N; i ++)
s += 'a';
}
} cout << s << endl;
}
return 0;
}
被期末论文大作业支配的一周!!!好久没写题了
CodeForces Round #527 (Div3) A. Uniform String的更多相关文章
- CodeForces Round #527 (Div3) C. Prefixes and Suffixes
http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...
- CodeForces Round #527 (Div3) B. Teams Forming
http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...
- CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)
http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...
- CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)
http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- Codeforces Round #527 (Div. 3)
一场div3... 由于不计rating,所以打的比较浪,zhy直接开了个小号来掉分,于是他AK做出来了许多神仙题,但是在每一个程序里都是这么写的: 但是..sbzhy每题交了两次,第一遍都是对的,结 ...
- Codeforces Round #527 -A. Uniform String(思维)
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
随机推荐
- 11-while循环基本使用
hm_02_第一个while循环.py def main(): i = 1 while i <= 3: print(i, 'Hello world') i += 1 print(i) 1 Hel ...
- A1038
用一串数拼接成一个数,输出最小的. 思路:使用string和相关的函数. #include<iostream> #include<cstdio> #include<str ...
- 郁金香指标开源库的使用--(tulipindicators-0.8.4)
瞎逛发现最新出了这么一个指标库,有100多种指标的函数库,文档写的比较好,重要的是作者一直在维护. 把它编成库,然后测试一下,可用于自动交易,策略交易等开发. 1.下载地址 https://githu ...
- 那些年我们追过的C#奇葩关键字——忐忑
说到中国的歌坛,不能光说张学友这种大咖吧,我看那些怪咖更给力,比如我们的龚琳娜童鞋,一首神曲<忐忑>唱的那叫不可收拾,而且听到的改编版本更多,每一次都是心怀忐忑,就像C#里的那些关键字 说 ...
- SVN-Tips
一些实际使用中遇到与学习的SVN的TIPS 1.如何从SVN检出maven项目: 1.从svn导入“作为工作空间中的项目检出”--->Finish 2.如“1”操作后,会自动的在MyEclips ...
- 【课堂实践】Myod和Mycp
实验内容 编写MyOD.java 用java MyOD XXX实现Linux下od -tx -tc XXX的功能 实验代码 od.java 截图 遇到的问题及解决办法 一开始想的方向是将得出的功能结果 ...
- 安装虚拟机&Linux命令学习
安装虚拟机&Linux命令学习 基于VirtualBox虚拟机安装Ubuntu 1.下载安装VirtualBox 根据自己电脑(32位操作系统)的实际情况,我在网上找了相应的VirtualBo ...
- # C语言假期学习笔记——6
C语言假期学习笔记--6 数组 主要学习了一位数组和二维数组. 数组是一组具有相同类型的变量的集合.C语言程序通过元素的下标来访问数组中的元素.(下标从0开始) 一位数组 类型 数组名[元素个数] 二 ...
- 【SDOI2014】数表
题面 题解 不管$a$的限制 我们要求的东西是:($\sigma(x)$是$x$的约数个数和) $ \sum_{i=1}^n\sum_{j=1}^m\sigma(gcd(i,j)) $ 设$f(x)= ...
- 【BZOJ4698】[SDOI2008]Sandy的卡片
[BZOJ4698][SDOI2008]Sandy的卡片 题面 flag倒了. bzoj 洛谷 题解 首先题目的区间加很丑对吧, 将每个串差分一下,就可以转化为 求: 给定\(N\)个串,求他们的最长 ...