Codeforces Round #634 (Div. 3) B. Construct the String//贪心

题目
Codeforces Round #634 (Div. 3) B. Construct the String//贪心_第1张图片
Codeforces Round #634 (Div. 3) B. Construct the String//贪心_第2张图片
题意:给你一个n长度的字符串,要求每a个长度的子串中要有b个不同的字符

思路:既然只能有b个不同的字符,那么我们干脆就只用b个不同的字符来构造n长度的字符串,不就好了。

#include 
using namespace std;
#define NewNode (ListNode *)malloc(sizeof(ListNode))
#define Mem(a,b) memset(a,b,sizeof(a))
const int N = 2e5 + 50;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const unsigned long long mod = 998244353;
const int II = 3.1415926535;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> pii;
int main()
{
     
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    ll t;
    cin >> t;
    while(t--)
    {
     
        int n,a,b;
        cin >> n >> a >> b;
        string s = "abcdefghijklmnopqrstuvwxyz";
        int num = n/b;//得控制不要超了n长度
        for(int i = 0;i < num;i++)
            cout << s.substr(0,b);
        if(n % b != 0)
        {
     
            int k = n%b;
            cout << s.substr(0,k);
        }
        cout << endl;
    }
}

你可能感兴趣的:(codeforces,贪心)