限时10s,所以不用考虑什么算法了,暴力吧
分别按照3x3视野的四个方向去地图上匹配,把符合的地点标记出来,最后统一按照从上到下,从左到右的顺序输出。
代码:
#include <iostream> using namespace std; #define MAP_SIZE 250 bool match(char map[MAP_SIZE][MAP_SIZE], char sight[][], int r, int c) {
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
if (map[r + i][c + j] != sight[i][j])
return false;
return true;
} void find(char map[MAP_SIZE][MAP_SIZE], char sight[][], char res[MAP_SIZE][MAP_SIZE], int N, int M) {
for (int i = ; i < N - ; i++) {
for (int j = ; j < M - ; j++) {
if (match(map, sight, i, j))
res[i + ][j + ] = ;
}
}
} void rotate(char sight[][]) {
for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
swap(sight[i][j], sight[ - j][ - i]);
for (int i = ; i < ; i++)
swap(sight[][i], sight[][i]);
} int main() {
int N, M;
char map[MAP_SIZE][MAP_SIZE];
char res[MAP_SIZE][MAP_SIZE];
char sight[][]; cin >> N >> M;
for (int i = ; i < N; i++)
for (int j = ; j < M; j++)
cin >> map[i][j]; for (int i = ; i < ; i++)
for (int j = ; j < ; j++)
cin >> sight[i][j]; memset(res, , MAP_SIZE * MAP_SIZE * sizeof(char)); for (int i = ; i < ; i++) {
find(map, sight, res, N, M);
rotate(sight);
} for (int i = ; i < N - ; i++)
for (int j = ; j < M - ; j++)
if (res[i][j])
cout << i + << " " << j + << endl; return ;
}