返回结果每次女必须ngbfdgsda

陈思润  •  1个月前


include <bits/stdc++.h>

using namespace std; const int N = 1005; char mat[N][N]; int book[N][N], n, m;

int main() {

int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
	for (int j = 1; j <= m; j++) {
		cin >> mat[i][j];
	}
}
for (int i = 1; i <= n; i++) {
	for (int j = 1; j <= m; j++) {
		if (mat[i][j] == '1' || mat[i][j] == '7') {
			book[i][j] = 1;
			if (i + 1 <= n)
				book[i + 1][j] = 1;
			if (i - 1 >= 1)
				book[i - 1][j] = 1;
			if (j + 1 <= m)
				book[i][j + 1] = 1;
			if (j - 1 >= 1)
				book[i][j - 1] = 1;
		}
		if (mat[i][j] == '2') {
			book[i][j] = 1;
			for (int k = i - 1; k >= 1; k--) {
				if (mat[k][j] != '0')
					break;
				book[k][j] = 1;
			}
			for (int k = i + 1; k <= n; k++) {
				if (mat[k][j] != '0')
					break;
				book[k][j] = 1;
			}
			for (int k = j - 1; k >= 1; k--) {
				if (mat[i][k] != '0')
					break;
				book[i][k] = 1;
			}
			for (int k = j + 1; k <= m; k++) {
				if (mat[i][k] != '0')
					break;
				book[i][k] = 1;
			}
		}
		if (mat[i][j] == '3') {
			book[i][j] = 1;
			if (i - 2 >= 1 && j - 1 >= 1 && mat[i - 1][j] == '0')
				book[i - 2][j - 1] = 1;
			if (i - 1 >= 1 && j - 2 >= 1 && mat[i][j - 1] == '0')
				book[i - 1][j - 2] = 1;
			if (i + 1 <= n && j - 2 >= 1 && mat[i][j - 1] == '0')
				book[i + 1][j - 2] = 1;
			if (i + 2 <= n && j - 1 >= 1 && mat[i + 1][j] == '0')
				book[i + 2][j - 1] = 1;
			if (i + 2 <= n && j + 1 <= m && mat[i + 1][j] == '0')
				book[i + 2][j + 1] = 1;
			if (i + 1 <= n && j + 2 <= m && mat[i][j + 1] == '0')
				book[i + 1][j + 2] = 1;
			if (i - 1 >= 1 && j + 2 <= m && mat[i][j + 1] == '0')
				book[i - 1][j + 2] = 1;
			if (i - 2 >= 1 && j + 1 <= m && mat[i - 1][j] == '0')
				book[i - 2][j + 1] = 1;
		}
		if (mat[i][j] == '4') {
			book[i][j] = 1;
			int flag = 0;
			for (int k = i - 1; k >= 1; k--) {
				if (flag == 0 && mat[k][j] != '0')
					flag = 1;
				else if (flag == 1 && mat[k][j] == '0')
					book[k][j] = 1;
				else if (flag == 1 && mat[k][j] != '0')
					break;
			}
			flag = 0;
			for (int k = i + 1; k <= n; k++) {
				if (flag == 0 && mat[k][j] != '0')
					flag = 1;
				else if (flag == 1 && mat[k][j] == '0')
					book[k][j] = 1;
				else if (flag == 1 && mat[k][j] != '0')
					break;
			}
			flag = 0;
			for (int k = j - 1; k >= 1; k--) {
				if (flag == 0 && mat[i][k] != '0')
					flag = 1;
				else if (flag == 1 && mat[i][k] == '0')
					book[i][k] = 1;
				else if (flag == 1 && mat[i][k] != '0')
					break;
			}
			flag = 0;
			for (int k = j + 1; k <= m; k++) {
				if (flag == 0 && mat[i][k] != '0')
					flag = 1;
				else if (flag == 1 && mat[i][k] == '0')
					book[i][k] = 1;
				else if (flag == 1 && mat[i][k] != '0')
					break;
			}
		}
		if (mat[i][j] == '5') {
			book[i][j] = 1;
			if (i - 2 >= 1 && j - 2 >= 1 && mat[i - 1][j - 1] == '0')
				book[i - 2][j - 2] = 1;
			if (i - 2 >= 1 && j + 2 <= m && mat[i - 1][j + 1] == '0')
				book[i - 2][j + 2] = 1;
			if (i + 2 <= n && j - 2 >= 1 && mat[i + 1][j - 1] == '0')
				book[i + 2][j - 2] = 1;
			if (i + 2 <= n && j + 2 <= m && mat[i + 1][j + 1] == '0')
				book[i + 2][j + 2] = 1;
		}
		if (mat[i][j] == '6') {
			book[i][j] = 1;
			if (i - 1 >= 1 && j - 1 >= 1)
				book[i - 1][j - 1] = 1;
			if (i - 1 >= 1 && j + 1 <= m)
				book[i - 1][j + 1] = 1;
			if (i + 1 <= n && j - 1 >= 1)
				book[i + 1][j - 1] = 1;
			if (i + 1 <= n && j + 1 <= m)
				book[i + 1][j + 1] = 1;
		}
	}
}
int res = 0;
for (int i = 1; i <= n; i++) {
	for (int j = 1; j <= m; j++) {
		if (book[i][j] == 0) {
			res++;

// cout << 0;

		} else {

// cout << 1;

		}
	}//cout << endl;
}
cout << res;
return 0;

}


评论:

请先登录,才能进行评论