AT_abc383_b

· · 题解

题目传送门

思路

做题之前先看数据:

1\le H\le 10\\ 1\le W\le 10

所以直接暴力。

如何暴力?

枚举 i 和 j 表示第一个加湿器的位置,枚举 k 和 l 表示第二个加湿器的位置,如果当前位置不是空地那么就跳过,否则判断可以加湿的空地数,然后取个 \max。

AC Code

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

int h, w, d, ans;
char s[20][20];

int main() {
    scanf("%d%d%d", &h, &w, &d);
    for (int i = 1; i <= h; i++) 
        scanf("%s", s[i] + 1);
    for (int i = 1; i <= h; i++) 
        for (int j = 1; j <= w; j++) 
            for (int k = 1; k <= h; k++) 
                for (int l = 1; l <= w; l++) {
                    if (i == k && j == l) 
                        continue;
                    if (s[i][j] != '.' || s[k][l] != '.') 
                        continue;
                    int res = 0;
                    for (int a = 1; a <= h; a++) 
                        for (int b = 1; b <= w; b++) 
                            if (s[a][b] == '.' && (abs(i - a) + abs(j - b) <= d || abs(k - a) + abs(l - b) <= d)) 
                                res++;
                    ans = max(ans, res);
                }
    printf("%d\n", ans);
}