题目描述
看了半天才明白这道题到底要做什么事情,首先给你一个 (h+2)∗(w+2) ( h + 2 ) ∗ ( w + 2 ) 的 maze m a z e ,需要你对其进行涂色,涂色后满足每个一个点(包括它自己在内)共九个格子中的黑色格子的数目等于它自身所带的权值,如果不能涂色则输出 impossible i m p o s s i b l e 。
数据范围
分析
在一个九宫格中考虑最左上角的点,如果当前到这个点的权值没有变成 0 0 <script type="math/tex" id="MathJax-Element-160">0</script>,则说明这个点不能被之前已经涂色的点满足条件,则这个点就是需要涂色的点。
#include <bits/stdc++.h>
#define rep( i , l , r ) for( int i = (l) ; i <= (r) ; ++i )
#define per( i , r , l ) for( int i = (r) ; i >= (l) ; --i )
#define erep( i , u ) for( int i = head[(u)] ; ~i ; i = e[i].nxt )
using namespace std;
int _read(){
char ch = getchar();
int x = 0 , f = 1 ;
while( !isdigit( ch ) )
if( ch == '-' ) f = -1 , ch = getchar();
else ch = getchar();
while( isdigit( ch ) )
x = (ch - '0') + x * 10 , ch = getchar();
return x * f;
}
const int maxn = 400 + 5;
int c[maxn][maxn] , m[maxn][maxn];
int main(){
int h = _read() , w = _read();
rep( i , 1 , h + 2 )
rep( j , 1 , w + 2 ) c[i][j] = _read();
rep( i , 1 , h )
rep( j , 1 , w )
if( c[i][j] ){
m[i][j] = 1;
for( int k = i ; k <= i + 2 ; ++k )
for( int l = j ; l <= j + 2 ; ++l ) c[k][l]--;
}
rep( i , 1 , h + 2 )
rep( j , 1 , w + 2 )
if( c[i][j] ){
puts("impossible");
return 0;
}
rep( i , 1 , h ){
rep( j , 1 , w ) printf("%c" , m[i][j] ? 'X' : '.');
printf("\n");
}
return 0;
}