知识点:暴力,枚举
这个题还是比较简单的,分别从行列的方向枚举统计答案就行了,然后一个坑点是如果需要统计的长度是1的话,那么行列方向上会重复统计一倍的答案,所以这个点要注意,我还是没想到,WA了才发现
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
string s[N];
int main() {
int n, m, k;
cin >> n >> m >> k;
int ans = 0;
for (int i = 1; i <= n; i++) {
cin >> s[i];
s[i] = " " + s[i];
int cnt = 0;
for (int j = 1; j <= m; j++) {
if (s[i][j] == '.') cnt++;
else {
ans += max(0, cnt - k + 1);
cnt = 0;
}
}
if (cnt) ans += max(0, cnt - k + 1);
}
if (k == 1) { cout << ans; return 0; }
for (int i = 1; i <= m; i++) {
int cnt = 0;
for (int j = 1; j <= n; j++) {
if (s[j][i] == '.') cnt++;
else {
ans += max(0, cnt - k + 1);
cnt = 0;
}
}
if (cnt) ans += max(0, cnt - k + 1);
}
cout << ans;
return 0;
}