• 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;
     } 
  • 相关阅读:
    【PHP框架CodeIgniter学习】使用辅助函数—建立自己的JSONHelper
    mysql将字符转换成数字
    ***微信浏览器禁止app下载链接怎么办
    十分钟帮你拿到500万天使轮!手把手教你写商业计划书【干货】
    ***PHP各种编码的汉字字符串截取
    Nginx与Redis解决高并发问题
    hrtimer的简单使用 + 原理和实现【转】
    2.6 内核中的计时器和列表【转】
    Linux输入子系统:多点触控协议 -- multi-touch-protocol.txt【转】
    kthread_create与kernel_thread的区别【栈】
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781899.html
Copyright © 2020-2023  润新知