Codeforces Round #634 B. Construct the String(贪心)
题目描述
You are given three positive integers n n n , a a a and b b b . You have to construct a string s s s of length n n n consisting of lowercase Latin letters such that each substring of length a a a has exactly b b b distinct letters. It is guaranteed that the answer exists.
You have to answer t t t independent test cases.
Recall that the substring s[l…r] s[l \dots r] s[l…r] is the string sl,sl+1,…,sr s_l, s_{l+1}, \dots, s_{r} sl,sl+1,…,sr and its length is r−l+1 r - l + 1 r−l+1 . In this problem you are only interested in substrings of length a a a .
输入格式
The first line of the input contains one integer t t t ( 1≤t≤2000 1 \le t \le 2000 1≤t≤2000 ) — the number of test cases. Then t t t test cases follow.
The only line of a test case contains three space-separated integers n n n , a a a and b b b ( 1≤a≤n≤2000,1≤b≤min(26,a) 1 \le a \le n \le 2000, 1 \le b \le \min(26, a) 1≤a≤n≤2000,1≤b≤min(26,a) ), where n n n is the length of the required string, a a a is the length of a substring and b b b is the required number of distinct letters in each substring of length a a a .
It is guaranteed that the sum of n n n over all test cases does not exceed 2000 2000 2000 ( ∑n≤2000 \sum n \le 2000 ∑n≤2000 ).
输出格式
For each test case, print the answer — such a string s s s of length n n n consisting of lowercase Latin letters that each substring of length a a a has exactly b b b distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.
输入输出样例
4 7 5 3 6 1 1 6 6 1 5 2 2
tleelte qwerty vvvvvv abcde
说明/提示
In the first test case of the example, consider all the substrings of length 5 5 5 :
- "tleel": it contains 3 3 3 distinct (unique) letters,
- "leelt": it contains 3 3 3 distinct (unique) letters,
- "eelte": it contains 3 3 3 distinct (unique) letters.
直接构造循环节长度为b的字符串,比如n=7 b=3 就构造abcabca 这样能在尽可能短的距离内让不同字符出现的次数比较均匀。和a没啥关系。
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,a,b; scanf("%d%d%d",&n,&a,&b); int i,j; for(i=0;i<n;i++) { printf("%c",i%b+'a'); } cout<<endl; } }