题目链接:http://hihocoder.com/problemset/problem/1094
题意:矩阵里找3*3的子矩阵,按照某个点为中心四个方向的子矩阵符合就行。
枚举左上角的点,翻转判断即可。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int maxn = 220; 5 int n, m; 6 char G[maxn][maxn]; 7 char pos[5][5]; 8 bool f[10]; 9 10 bool check(int x, int y) { 11 memset(f, 0, sizeof(f)); 12 for(int i = 0; i < 3; i++) { 13 for(int j = 0; j < 3; j++) { 14 if(pos[i][j] != G[x+j][y+i]) f[0] = 1; 15 if(pos[i][j] != G[x+2-i][y+j]) f[1] = 1; 16 if(pos[i][j] != G[x+i][y+2-j]) f[2] = 1; 17 if(pos[i][j] != G[x+2-j][y+2-i]) f[3] = 1; 18 19 if(pos[i][j] != G[x+i][y+j]) f[4] = 1; 20 if(pos[i][j] != G[x+2-j][y+i]) f[5] = 1; 21 if(pos[i][j] != G[x+j][y+2-i]) f[6] = 1; 22 if(pos[i][j] != G[x+2-i][y+2-j]) f[7] = 1; 23 } 24 } 25 if(!(f[0]&&f[1]&&f[2]&&f[3]&&f[4]&&f[5]&&f[6]&&f[7])) return 1; 26 return 0; 27 } 28 29 int main() { 30 // freopen("in", "r", stdin); 31 while(~scanf("%d%d",&n,&m)) { 32 memset(G, 0, sizeof(G)); 33 memset(pos, 0, sizeof(pos)); 34 for(int i = 0; i < n; i++) scanf("%s", G[i]); 35 for(int i = 0; i < 3; i++) scanf("%s", pos[i]); 36 for(int i = 0; i < n; i++) { 37 for(int j = 0; j < m; j++) { 38 if(check(i, j)) { 39 printf("%d %d ", i+2, j+2); 40 } 41 } 42 } 43 } 44 return 0; 45 }