Files
python/TangDou/LuoGuBook/P3654.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

51 lines
1.2 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
char a[N][N];
//以i,j为坐标的点向右找k个看看是不是都是空地向下找k个看看是不是都是空地
int check(int i, int j, int k) {
int cnt = 0;
//向右
bool found = true;
for (int x = j; x < j + k; x++) {
if (a[i][x] != '.') {
found = false;
break;
}
}
if (found)cnt++;
//向下
found = true;
for (int x = i; x < i + k; x++) {
if (a[x][j] != '.') {
found = false;
break;
}
}
if (found)cnt++;
return cnt;
}
int r, c, K, ans;
int main() {
//篮球场是r行c列的矩阵
cin >> r >> c >> k;
//读入地图
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
cin >> a[i][j];
//遍历每一个位置,寻找连续空地
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++)
ans += check(i, j, k);
//特判(美女一个人,向右看一个是自己,向下看一个又是自己,数据就错误翻倍了~)
if (k == 1) cout << ans / 2 << endl;
else cout << ans << endl;
return 0;
}