zoukankan      html  css  js  c++  java
  • Construct the String CodeForces 1335B

    You are given three positive integers nn, aa and bb. You have to construct a string ss of length nn consisting of lowercase Latin letters such that each substring of length aa has exactly bb distinct letters. It is guaranteed that the answer exists.

    You have to answer tt independent test cases.

    Recall that the substring s[lr]s[l…r] is the string sl,sl+1,,srsl,sl+1,…,sr and its length is rl+1r−l+1. In this problem you are only interestd in substrings of length aa.

    Input

    The first line of the input contains one integer tt (1t20001≤t≤2000) — the number of test cases. Then tttest cases follow.

    The only line of a test case contains three space-separated integers nn, aa and bb (1an2000,1bmin(26,a)1≤a≤n≤2000,1≤b≤min(26,a)), where nn is the length of the required string, aa is the length of a substring and bb is the required number of distinct letters in each substring of length aa.

    It is guaranteed that the sum of nn over all test cases does not exceed 20002000 (n2000∑n≤2000).

    Output

    For each test case, print the answer — such a string ss of length nn consisting of lowercase Latin letters that each substring of length aa has exactly bb distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.

    Example

    Input
    4
    7 5 3
    6 1 1
    6 6 1
    5 2 2
    
    Output
    tleelte
    qwerty
    vvvvvv
    abcde
    

    Note

    In the first test case of the example, consider all the substrings of length 55:

    • "tleel": it contains 33 distinct (unique) letters,
    • "leelt": it contains 33 distinct (unique) letters,
    • "eelte": it contains 33 distinct (unique) letters.
    #include <bits/stdc++.h>
    typedef long long ll;
    using namespace std;
    const ll inf = 1e18;
    const int mod = 1000000007;
    const int mx = 100; //check the limits, dummy
    typedef pair<int, int> pa;
    const double PI = acos(-1);
    ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
    #define swa(a,b) a^=b^=a^=b
    #define re(i,a,b) for(int i=(a),_=(b);i<_;i++)
    #define rb(i,a,b) for(int i=(b),_=(a);i>=_;i--)
    #define clr(a) memset(a, 0, sizeof(a))
    #define lowbit(x) ((x)&(x-1))
    #define mkp make_pair
    void sc(int& x) { scanf("%d", &x); }void sc(int64_t& x) { scanf("%lld", &x); }void sc(double& x) { scanf("%lf", &x); }void sc(char& x) { scanf(" %c", &x); }void sc(char* x) { scanf("%s", x); }
    ll  m, n,t,x,k,ans=0,sum=0;
    ll a, b;
    char s[mx];
    int main()
    {
        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        cin >> t;
    
        while (t--) {
            
            cin >> n>>a>>b;
            string s(a, ' ');
            re(i, 0, a)s[i] = (char)('a' + i % b);
            re(i, 0, n)cout << s[i%a]; cout << endl;
        }
    }
  • 相关阅读:
    操作 Java 数组的 12 个最佳方法
    详解 JavaScript 中 splice() 方法
    Java 读取 .properties 配置文件的几种方式
    表单中单选、多选、选择框值的获取及表单的序列化
    一个调出上下文菜单的实例
    跨浏览器的事件侦听器和事件对象
    动态加载js和css
    php语言实现的7种基本的排序方法
    CORS(跨源资源共享)实战
    ubuntu中LAMP环境搭建及ubuntu语言和输入法设置
  • 原文地址:https://www.cnblogs.com/xxxsans/p/12695820.html
Copyright © 2011-2022 走看看