zoukankan      html  css  js  c++  java
  • 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 construct such a string ss of length nn that for each ii from 11 to kk 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 tindependent queries.

    Input

    The first line of the input contains one integer tt (1t1001≤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 (1ni100,1kimin(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 22, 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 11).

    In the third example query any permutation of the given answer is acceptable (the maximum minimal frequency is 33).

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int T;
    
    int main() {
        scanf("%d", &T);
        while(T --) {
            int N, K;
            scanf("%d%d", &N, &K);
            string s = "";
            if(K > N) {
                for(int i = 0; i < N; i ++)
                    s += ('a' + i);
            } else {
                int cnt = N / K;
                for(int i = 0; i < cnt; i ++) {
                    for(int j = 0; j < K; j ++)
                        s += ('a' + j);
                }
    
                if(N % K) {
                    N = N - K * cnt;
                    for(int i = 0; i < N; i ++)
                        s += 'a';
                }
            }
    
            cout << s << endl;
        }
        return 0;
    }
    

      被期末论文大作业支配的一周!!!好久没写题了

  • 相关阅读:
    CC3000 SmartConfig
    谈谈几个月以来开发android蓝牙4.0 BLE低功耗应用的感受
    CC3000 SPI接口编程介绍
    cc3000+LM3S9B96
    CC3000 主机驱动API介绍
    Wi-FiR CC3000 模块
    修改远程桌面连接端口及修改端口号后如何连接!
    电脑网线/水晶头的连接方法(A类,B类)
    快速切换IP的批处理!
    IE打开报错,提示该内存不能为read的解决办法!
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/10183878.html
Copyright © 2011-2022 走看看