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 ...
随机推荐
- python多进程详解和协程
1.由于python多线程适合于多IO操作,但不适合于cpu计算型工作,这时候可以通过多进程实现.python多进程简单实用 # 多进程,可以cpu保持一致,python多线程适合多io.对于高cpu ...
- 中国大学MOOC-JAVA学习(浙大翁恺)—— 信号报告
使用switch-case语句的练习 import java.util.Scanner; public class Main { public static void main(String[] ar ...
- java基础之while循环练习(2)
实现猜数游戏,如果没有猜对随机数,则程序继续,猜对后停止程序. 方法思路: 1:要产生一个随机数,所以需要创建一个随机数对象 Random random=new Random(): 2: 调用随机数对 ...
- 加分项——C语言实现Linux的pwd命令
加分项--C语言实现Linux的pwd命令 实现要求 1 学习pwd命令 2 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 3 实现mypwd 4 测试mypwd pwd pw ...
- 20155223 2016-2017-2 《Java程序设计》第10周学习总结
20155223 2016-2017-2 <Java程序设计>第10周学习总结 教材学习内容总结 Java Socket编程 网络上的两个程序通过一个双向的通讯连接实现数据的交换,这个双向 ...
- 20155330 2016-2017-2 《Java程序设计》第九周学习总结
20155330 2016-2017-2 <Java程序设计>第九周学习总结 教材学习内容总结 学习目标 了解JDBC架构 掌握JDBC架构 掌握反射与ClassLoader 了解自定义泛 ...
- 20155336 2016-2017-2 《Java程序设计》第四周学习总结
20155336 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 第六章 继承:面向对象中,为避免多个类间重复定义共同行为.(简单说就是将相同的程序代码提升为 ...
- Centos安装man功能
CentOS接触很久了,但是一直作为服务器端使用.这次之所以安装man,是由于开始学习Nginx了. 言归正传,安装man,首先得下载包.由于我们天朝的原因,代码包几乎下不到的.首先你得FQ,再下载, ...
- mysql导入报错【The MySQL server is running with the --event-scheduler=DISABLED】
一.问题: 在进行mysql操作导入库的时候,报出了[The MySQL server is running with the --event-scheduler=DISABLED] 查看后台日志是事 ...
- lnmp环境搭建(centos6.9+mysql5.7+php7.1+nginx1.10)
安装前准备:CentOS 6.9 64位 最小化安装 yum install -y make gcc gcc-c++ perl zlib-devel libaio libpng libpng-deve ...