http://poj.org/problem?id=1970
![](https://img.haomeiwen.com/i6745450/957db7e9bda7d7da.png)
注意点:实际上搜索四个方向就够了, 左上,右, 左下, 下
要注意六个点的情况,所以要沿着反向再查一下
//
// Created by ljs on 2018/8/28.
//
#include <iostream>
using namespace std;
int m = 19, n = 19;
int dir[4][4] = {{1, 0}, {-1, 1},{0, 1}, {1, 1}};
int count;
bool flag;
int maze[19][19];
void dfs(int x, int y, int cur, int maze[19][19], int d, int team){
int xx = x + dir[d][0];
int yy = y + dir[d][1];
if(maze[xx][yy] == team && xx >= 0 && xx < m && yy >= 0 && yy < n ){
count++;
dfs(xx, yy, cur + 1, maze, d, team);
}
}
int main(){
int t;
cin>>t;
while(t--){
for(int i = 0; i < 19; i++){
for(int j = 0; j < 19; j++){
cin>>maze[i][j];
}
}
flag = false;
count = 0;
for(int i = 0; i < 19; i++){
for(int j = 0; j < 19; j++){
if(maze[i][j] != 0){
for(int d = 0 ; d < 4; d++) {
count = 1;
dfs(i, j, 1, maze, d, maze[i][j]);
if (count == 5 && maze[i - dir[d][0]][j - dir[d][1]] != maze[i][j]) {
cout << maze[i][j] << endl;
cout << i + 1 << " " << j + 1 << endl;
flag = true;
break;
}
}
}
if(flag) break;
}
if(flag) break;
}
if(!flag)
cout<<0<<endl;
}
return 0;
}
网友评论