美文网首页
poj 1970 The Game

poj 1970 The Game

作者: 刘小小gogo | 来源:发表于2018-08-28 22:29 被阅读0次

http://poj.org/problem?id=1970

image.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;
}

相关文章

网友评论

      本文标题:poj 1970 The Game

      本文链接:https://www.haomeiwen.com/subject/kijcwftx.html