转自大牛BearChild:http://blog.csdn.net/keshuai19940722/article/details/49839359
这道题目在前些日子遇到过几乎是一模一样的,当时有两个版本,第一个版本写出来了的,还写了博客:http://blog.csdn.net/yick_liao/article/details/49685217 。现在想想,自己都哭笑不得。很遗憾第二个版本我始终没有推出来,看了大牛的博客才恍然大悟!
总结,构造一定要明确目的、明确方向,盲目的尝试,只是徒增笑耳罢了!
感谢大牛,你是我心中的神,一个月100+的题量,真的是佩服得五体投地!!!
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int T;
cin >> T;
for (int I = 1; I <= T; ++I) {
cout << "Case #" << I << ":" << endl;
int N, M, K;
cin >> N >> M >> K;
string ans;
if (N < M) ans = "Impossible";
else if (N == M) for (int i = 0; i < N; ++i) ans += 'A';
else if (K == 1) ans = "Impossible";
else if (K >= 3) {
if (M < 3) ans = "Impossible";
else {
int t = M - 3;
for (int i = 0; i <= t; ++i) ans += 'A';
for (int i = 1; i < N - t; ++i) ans += 'A' + i % 3;
}
}
else {
if (N == 8 && M == 7) ans = "AABABBAA";
else if (M < 8) ans = "Impossible";
else {
int t = M - 8;
for (int i = 0; i <= t; ++i) ans += 'A';
string s("ABAABB");
for (int i = 1; i < N - t; ++i) ans += s[i % 6];
}
}
cout << ans << endl;
}
return 0;
}