HDU 5559 Frog and String

转自大牛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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值