個人博客鏈接: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;
}