0
点赞
收藏
分享

微信扫一扫

B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)

原理链接: ​​https://codeforces.com/problemset/problem/1328/B​​​B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define
测试样例:

Input
7
5 1
5 2
5 8
5 10
3 1
3 2
20 100
Output
aaabb
aabab
baaba
bbaaa
abb
bab
aaaaabaaaaabaaaaaaaa

题意: 给你一个长为B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_02的只由B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_03B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_ios_04B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_05B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_06组成,问字典序第B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_字典序_07小的字符串排列。

解题思路: 我们观察一下字符串,是不是B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_06排的越前,字典序越大。我们又知道这字典序似乎只跟B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_06的位置有关,我们假设一个B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_字典序_10是固定在倒数第B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_11位的,且设这个B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_字典序_10为排的最前的,那么剩下一个B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_字典序_10放后面的方法有B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_ios_14种,且放得越后字典序越小。如果我们对这第一个B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_06的位置进行分组,倒数第2位为第一组,循循推进,那么每组的方法数为B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_ios_16种,且如果是在这第B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_字典序_07组第一位,那么说明第2个B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_06就是在最后一个,同样也是这样推过去。通过这个信息,我们这个题目就很明了了,直接推出字典序第B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_字典序_07小的字符串中两个B. K-th Beautiful String(字符串+字典序)Codeforces Round #629 (Div. 3)_#define_06的位置,最后输出即可。

AC代码:

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t,n,k;
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>n>>k;
int cnt=2,sum=1;//cnt表示分组,因为用第一个b的下标来分组,这里我们利用倒数下标这个概念
while(k>sum){
k-=sum;
//每过一组组合数加1,b的倒数下标+1.
sum++;
cnt++;
}
//退出循环后,得到了第一个b的第二个b的位置。
rep(i,1,n){
if(n-i+1==cnt||n-i+1==k)cout<<"b";
else cout<<"a";
}
cout<<endl;
}
}
return 0;
}


举报

相关推荐

0 条评论