P3654 First Step (ファーストステップ)
题目传送门
#include
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;
}