Educational Codeforces Round 88 (Rated for Div. 2) B. New Theatre Square

题目链接:https://codeforces.com/contest/1359/problem/B

题解

因为 $1 \times 2$ 的瓷砖不能旋转,所以每次逐行考虑即可,注意 $y$ 取 $min(2x, y)$ 。

代码

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, m, x, y; cin >> n >> m >> x >> y;
    y = min(2 * x, y);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        for (int j = 0; j < m; j++) {
            if (s[j] == '.') {
                if (j + 1 < m and s[j + 1] == '.')
                    ans += y, ++j;
                else 
                    ans += x;
            }
        }
    }
    cout << ans << "\n";
}

int main() {
    int t; cin >> t;
    while (t--) solve();
}

 

上一篇:NOI Online 2020 #1(入门组) 题解


下一篇:Codeforces Round #651 (Div. 2) C. Number Game(数论)