• 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[lr] 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 rl+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 1t2000 ) — 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) 1an2000,1bmin(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 n2000 ).

    输出格式

    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.

    输入输出样例

    输入 #1
    4
    7 5 3
    6 1 1
    6 6 1
    5 2 2
    输出 #1
    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;
        }
    }
  • 相关阅读:
    使用xtrabackup对MySQL进行备份和恢复
    魔棒工具RegionGrow算法简介
    编程之美扫雷篇
    从繁体字到书法
    谈读书如何才能提升你的工作能力
    魔兽争霸拼图照片一张
    做你心目中的达文西
    六一儿童节的礼物那些游戏中你不知道的玩法
    DIY手工制作Rhombicuboctahedron
    ul样式与jquery1.4.1冲突
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12695579.html
Copyright © 2020-2023  润新知