提交时间:2024-01-21 22:31:24

运行 ID: 121541

#include <bits/stdc++.h> using namespace std; int a [32] [32] , b [32] [32] ; int dx [5] = { 0 , -1 , 1 , 0 , 0 } ; int dy [5] = { 0 , 0 , 0 , -1 , 1 } ; int n , sum = 0 ; void dfs ( int x , int y ) { if ( x < 0 || x > n + 1 || y < 0 || y > n + 1 || a [x] [y] == 2 ) { return ; } a [x] [y] = 1 ; int a = 4 ; while ( a -- ) { dfs ( x + dx [a] , y + dy [a] ) ; } return ; } int main ( ) { for ( int i = 1 ; i <= 10 ; i ++ ) for ( int j = 1 ; j <= 10 ; j ++ ) { cin >> b [i] [j] ; if ( ! b [i] [j] ) { a [i] [j] = 0 ; } else { a [i] [j] = 2 ; } } dfs ( 0 , 0 ) ; cout << endl ; for ( int i = 1 ; i <= 10 ; i ++ ) { for ( int j = 1 ; j <= 10 ; j ++ ) { if ( a [i] [j] ) { cout << "X " ; sum ++ ; } else { cout << a [i] [j] << ' ' ; } } cout << endl ; } cout << sum << endl ; return 0 ; }