Codeforces Round #527 -A. Uniform String(思维)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given two integers n and k.
Your task is to construct such a string ss of length nn that for each ii from 1to k 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.
Input
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.
Output
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.
Example
input
Copy
3
7 3
4 4
6 2
output
Copy
cbcacab
abcd
baabab
Note
In the first example query the maximum possible minimal frequency is 2, 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 1).
In the third example query any permutation of the given answer is acceptable (the maximum minimal frequency is 3).
题解:找到最大可能的值,这个值等于ni/ki,然后按照26个字母的顺序从大往小了输,最后的剩下的输a
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a,b;
char c[26];
for(int t=0;t<26;t++)
{
c[t]='a'+t;
}
int sum;
for(int t=0;t<n;t++)
{
cin>>a>>b;
sum=a;
for(int m=b-1;m>=0;m--)
{
for(int j=0;j<a/b;j++)
{
cout<<c[m];
sum--;
}
}
for(int m=0;m<sum;m++)
{
cout<<c[0];
}
cout<<endl;
}
return 0;
}
Codeforces Round #527 -A. Uniform String(思维)的更多相关文章
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #527 (Div. 3)
一场div3... 由于不计rating,所以打的比较浪,zhy直接开了个小号来掉分,于是他AK做出来了许多神仙题,但是在每一个程序里都是这么写的: 但是..sbzhy每题交了两次,第一遍都是对的,结 ...
- Educational Codeforces Round 40 C. Matrix Walk( 思维)
Educational Codeforces Round 40 (Rated for Div. 2) C. Matrix Walk time limit per test 1 second memor ...
- 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 c ...
- Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...
- Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...
- Codeforces Round #527 (Div. 3)C(多重集,STRING)
#include<bits/stdc++.h>using namespace std;const int maxn=1e6+7;pair<string,int>p[maxn]; ...
- Codeforces Round #527 (Div. 3) C. Prefixes and Suffixes (思维,字符串)
题意:给你某个字符串的\(n-1\)个前缀和\(n-1\)个后缀,保证每个所给的前缀后缀长度从\([1,n-1]\)都有,问你所给的子串是前缀还是后缀. 题解:这题最关键的是那两个长度为\(n-1\) ...
- Codeforces Round #527 (Div. 3)D2(栈,思维)
#include<bits/stdc++.h>using namespace std;int a[200007];stack<int>s;int main(){ int ...
随机推荐
- 金色酒类企业dedecms模板
金色酒类企业dedecms模板,网站模板,dedecms模板. 模板地址:http://www.huiyi8.com/sc/7276.html
- [Shell]Tetris Game
这篇文章主要介绍Shell脚本编写俄罗斯方块的方法,原文来自脚本之家,http://www.jb51.net/article/48926.htm 效果图: 代码: #!/bin/bash # Tetr ...
- HihoCoder1650 : 扁平化管理([Offer收割]编程练习赛38)(二分)
描述 小Hi的公司包括CEO在内一共有N名员工.这N名员工的上下级关系形成树形结构,CEO处于树根,普通员工处于叶子节点. 现在公司希望管理扁平化,要求树形结构中的层级不超过L层.此外,假设A是B的直 ...
- 【LeetCode】026. Remove Duplicates from Sorted Array
题目: Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- EntityFramework Code First 构建外键关系,数据库不生成外键约束
创建 ExtendedSqlGenerator类 public class ExtendedSqlGenerator : SqlServerMigrationSqlGenerator { #regio ...
- bzoj 3456 城市规划 —— 分治FFT / 多项式求逆 / 指数型生成函数(多项式求ln)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3456 首先考虑DP做法,正难则反,考虑所有情况减去不连通的情况: 而不连通的情况就是那个经典 ...
- Jasper:用户指南 / 设备 / 生命周期管理 / SIM 卡状态
ylbtech-Jasper:用户指南 / 设备 / 生命周期管理 / SIM 卡状态 1.返回顶部 1. SIM 卡状态 每个设备都有一个状态,决定了它能否在网络上建立数据连接,并且会影响设备是否计 ...
- Jmeter-调整占用内存解决内存溢出
启动jmeter.从启动jmeter的输出就可以看到,Modify HEAP “” in the jmeter batch file -Xmx512m -Xms512m -Xms是初始内存,-X ...
- JS---设计简易日历
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- js中关于事件捕获与事件冒泡的小实验
1.事件冒泡:事件按照从最特定的事件目标到最不特定的事件目标(document对象)的顺序触发. IE 5.5: div -> body -> document IE 6.0: div - ...