个人博客链接:https://blog.nuoyanli.com/2020/03/27/cf1328b/
题目链接
http://codeforces.com/contest/1328/problem/B
题意
组数据,每次给你两个数 ,问你由 个 和 个 组成的字符串的第 小的字典序的字符串是什么。
思路
我们通过观察可以知道规律,1+2+3+…+n,符合前 项和的部分规律,第 个串由两个 的位置唯一确定,由后往前找第一个 的位置,这个位置就是前 项和大于 的位置,第二个位置就是前 项和与 的差,详细见代码。
参考代码
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define PB push_back
#define FI first
#define SE second
#define m_p(a, b) make_pair(a, b)
const double pi = acos(-1.0);
const double eps = 1e-9;
typedef long long LL;
const int N = 1e6 + 10;
const int M = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double f = 2.32349;
void solve() {
IOS;
int t;
cin >> t;
while (t--) {
LL n, k;
cin >> n >> k;
int x = 0, y = 0;
while (1) {
y++;
x = y * (y + 1) / 2;
if (x >= k) {
break;
}
}
x = y * (y - 1) / 2;
x = k - x;
cout << x << " " << y << endl;
y = n - y;
x = n + 1 - x;
cout << x << " " << y << endl;
for (int i = 1; i <= n; i++) {
if (i == x || i == y) {
cout << "b";
} else {
cout << "a";
}
}
cout << endl;
}
}
signed main() {
solve();
return 0;
}