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

hamayanhamayan's blog

机の配置 [Kotamanegi Online Judge No.69]

https://kotamanegi.com/Problems/view/index.php?page=69

解法

https://kotamanegi.com/Submission/view/index.php?SubmissionID=1603

実装問題。
机をどう配置すれば最適かという問題もあるが、これは詰めるようにして置いていけばいい。
縦1横iの机を配置していくことを考える。
毎回、FをFFにコピーして作業していこう。

int N, H, W;
string F[10], FF[10];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> H >> W;
    rep(y, 0, H) cin >> F[y];

    rep(i, 1, N + 1) {
        int ans = 0;
        rep(y, 0, H) FF[y] = F[y];
        rep(y, 0, H) rep(x, 0, W - i + 1) {
            int ok = 1;
            rep(xx, x, x + i) if (FF[y][xx] == '#') ok = 0;
            if (ok) {
                ans++;
                rep(xx, x, x + i) FF[y][xx] = '#';
            }
        }
        printf("%d\n", ans);
    }
}