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 ...
随机推荐
- Android窗口系统第三篇---WindowManagerService中窗口的组织方式
Android窗口系统第一篇—Window的类型与Z-Order确定 Android窗口系统第二篇—Window的添加过程 上面文章梳理了一个窗口的添加过程,系统中有很多应用,每个应用有多个Activ ...
- test pic重复
- ES禁用_source不会影响聚合
From Elasticsearch's website: The _source field contains the original JSON document body that was pa ...
- BZOJ_2111_[ZJOI2010]Perm 排列计数_树形DP+组合数学
Description 称一个1,2,...,N的排列P1,P2...,Pn是Magic的,当且仅当2<=i<=N时,Pi>Pi/2. 计算1,2,...N的排列中有多少是Magic ...
- 【Lintcode】118.Distinct Subsequences
题目: Given a string S and a string T, count the number of distinct subsequences of T in S. A subseque ...
- js跨域请求方式 ---- JSONP原理解析
这篇文章主要介绍了js跨域请求的5中解决方式的相关资料,需要的朋友可以参考下 跨域请求数据解决方案主要有如下解决方法: 1 2 3 4 5 JSONP方式 表单POST方式 服务器代理 H ...
- 理解I/O Completion Port(完成端口)
欢迎阅读此篇IOCP教程.我将先给出IOCP的定义然后给出它的实现方法,最后剖析一个Echo程序来为您拨开IOCP的谜云,除去你心中对IOCP的烦恼.OK,但我不能保证你明白IOCP的一切,但我会尽我 ...
- .net 开源工具集1 (SQL,报表,Cube,Office导出)
http://www.cnblogs.com/asxinyu/p/dotnet_opensource_project_3.html
- 清除@SessionAttributes 网站实现退出登录
在网站实现登录时,我认识了@SessionAttributes,对我来说是真的好用,@SessionAttributes注解可以使得模型中的数据存储一份到session域中. 这样在页面跳转时可以直接 ...
- ObservableCollection排序
ObservableCollection没有自带的sort排序功能,那么可以写一个扩展方法: public static void Sort<T>(this ObservableColle ...