标签:
2 3 .## ..# #.. 0 0 2 2 5 ..... ###.# ..#.. ###.. ...#. 0 0 4 0
YES NO
———————————————————分割线————————————————————
#include "bits/stdc++.h" using namespace std ; const int maxN = 1100 ; char mp[ maxN ][ maxN ] ; bool limit [ maxN ][ maxN ] ; int destination_x , destination_y ; bool Get_Target ; void DFS ( const int N , const int xi , const int yi ) { if ( Get_Target ) return ; if ( xi == destination_x && yi == destination_y ) { Get_Target = true ; cout << "YES" << endl ; return ; } if ( mp[ xi ][ yi ] == ‘#‘ ) return ; if ( !limit[ xi ][ yi ] ) return ; else { mp[ xi ][ yi ] = ‘#‘ ; if ( limit[ xi - 1 ][ yi ] ) DFS ( N , xi - 1 , yi ) ; if ( limit[ xi + 1 ][ yi ] ) DFS ( N , xi + 1 , yi ) ; if ( limit[ xi ][ yi - 1 ] ) DFS ( N , xi , yi - 1 ) ; if ( limit[ xi ][ yi + 1 ] ) DFS ( N , xi , yi + 1 ) ; } } void Re_Init ( int n ) { for ( int i=0 ; i<n ; ++i ) { for ( int j=0 ; j<n ; ++j ) { limit [ i ][ j ] = true ; } } } int main ( ) { int T ; scanf ( "%d" , &T ) ; while ( T-- ) { int N , start_x , start_y ; Get_Target = false ; scanf ( "%d" , &N ) ; Re_Init ( N ) ; getchar ( ) ; for ( int i=0 ; i<N ; ++i ) { for ( int j=0 ; j<N ; ++j ) { mp[ i ][ j ] = getchar ( ) ; } getchar ( ) ; } scanf ( "%d%d%d%d" , &start_x , &start_y , &destination_x , &destination_y ) ; if ( mp[ start_x ][ start_y ] == ‘#‘ || mp[ destination_x ][ destination_y ] == ‘#‘ ) {cout << "NO" << endl ;continue ;} DFS ( N , start_x , start_y ) ; if ( !Get_Target ) cout << "NO" << endl ; memset ( limit , false , sizeof ( limit ) ) ; } return 0; }
2016-10-18 16:57:44
(完)
标签:
原文地址:http://www.cnblogs.com/shadowland/p/5973989.html