はまやんはまやんはまやん

hamayanhamayan's blog

回転拡大 [yukicoder No.565]

https://yukicoder.me/problems/no/565

解説放送

未定

解説

https://yukicoder.me/submissions/203586

実装が難しい問題。
回転の関数(rotate関数)と拡大(scale関数)を作る。
拡大はそんなに難しくないが、回転はやっかい。
自分は全て場合分けして解いたが、実装が早いプロは90度回転のみ実装して、180と270はそれを2回、3回適用している。
流石。

void print(vector<string> C) {
    int H = C.size();
    rep(y, 0, H) cout << C[y] << endl;
}
//---------------------------------------------------------------------------------------------------
vector<string> rotate(vector<string> C, int R) {
    if (R == 0) return C;

    int H = C.size();
    int W = C[0].length();

    if (R == 90) {
        vector<string> res(W);
        rep(y, 0, W) {
            res[y] = "";
            rep(x, 0, H) res[y] += C[H - 1 - x][y];
        }
        return res;
    }

    if (R == 180) {
        vector<string> res(H);
        rep(y, 0, H) {
            res[y] = "";
            rep(x, 0, W) res[y] += C[H - 1 - y][W - 1 - x];
        }
        return res;
    }

    if (R == 270) {
        vector<string> res(W);
        rep(y, 0, W) {
            res[y] = "";
            rep(x, 0, H) res[y] += C[x][W - 1 - y];
        }
        return res;
    }

    return C;
}
//---------------------------------------------------------------------------------------------------
vector<string> scale(vector<string> C, int K) {
    int H = C.size();
    int W = C[0].size();

    vector<string> res(H * K);
    rep(y, 0, H * K) rep(x, 0, W * K) res[y] += C[y / K][x / K];
    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    int R, K, H, W;
    cin >> R >> K >> H >> W;
    vector<string> C(H);
    rep(y, 0, H) cin >> C[y];

    C = rotate(C, R);
    C = scale(C, K);
    print(C);
}