解析,枚举法,详见代码:
#include<bits/stdc++.h>
using namespace std;
int t, n, m;
string s[105];
bool check(int x, int y) {
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
if (i == 0 || i == 3 || j == 0 || j == 3) {
//外框如果为1,不满足
if(s[i + x][j + y] == '1') return false;
} else {
//中心如果为0,不满足
if(s[i + x][j + y] == '0') return false;
}
}
}
return true;
}
int main() {
cin >> t;
while(t--) {
cin >> n >>