T625407 字符的洞
题目描述
在由 个大写英文字母( 到 )连接而成的字符串中,将“各字符的洞的数量”之和为 的字符串设为 。请找出在可能作为 的字符串中,字典序最小的那个字符串。
洞的数量为 的大写英文字母有……、、、、、、、、、、、、、、、、、、。
洞的数量为 的大写英文字母有……、、、、、。
洞的数量为 的大写英文字母有……。
输入格式
两个整数 和 。
输出格式
满足要求的字符串 。
输入输出样例 #1
输入 #1
5 6输出 #1
AAAAB输入输出样例 #2
输入 #2
2 1输出 #2
AC输入输出样例 #3
输入 #3
4 8输出 #3
BBBB说明/提示
保证 ,。
题解:
对于第三种情况:
不妨设数量为,为,
得
化简,得
AC Code
#include<bits/stdc++.h>
using namespace std;
int n,d,x,y;
int main() {
//freopen("hole.in","r",stdin);
//freopen("hole.out","w",stdout);
cin>>n>>d;
if(d==0){
for(int i=1;i<=n;i++){
cout<<"C";
}
}
else if(d<=n){
for(int i=1;i<=n;i++){
if(i<=d){
cout<<"A";
}
else{
cout<<"C";
}
}
}
else{
y=d-n;
x=2*n-d;
for(int i=1;i<=x;i++){
cout<<"A";
}
for(int i=1;i<=y;i++){
cout<<"B";
}
}
return 0;
}