Files
python/GESP/Level4/GESP202409/20240906_4_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

78 lines
1.3 KiB
C++
Raw 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;
//注意:n,m一定要声明在全局变量区!!!!因为check() 函数需要读取它的内容!!!
int n, m;
int a[N][N];
/*
测试用例:
3
1 4
0110
5 5
00000
01100
01100
00001
01100
5 5
00000
01100
01110
00001
01100
*/
bool check() {
//0:白 1:黑
if (n < 4 || m < 4 ) //不足4行4列,直接判定不可以,这步容易遗漏
return false;
int s1 = 0, s4 = 0;
for (int i = 1; i <= 4; i++) {
s1 += a[1][i];//第一行的和
s4 += a[4][i];//第四行的和
}
if (s1 || s4)//如果第一行或第四行不全是白色
return false;
//第2行,第3行
if (a[2][1] || a[2][4])//(2,1),(2,4)如果是黑色,
//判定不可以,注意:这里要写不可以的,保留最后的就是可以的
return false;
if (!a[2][2] || !a[2][3])
return false;
if (a[3][1] || a[3][4])
return false;
if (!a[3][2] || !a[3][3])
return false;
return true;
}
int main() {
int T;
cin >> T;
while (T--) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
string s;//因为01中间无空格,使用string进行读取,再分拆到数组a[N][N]中
cin >> s;
for (int j = 1; j <= m; j++)
a[i][j] = s[j - 1] - '0';//要注意string下标是从0开始的,这里j需要减1
}
if (check())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}