# Poj Solution 1110

```http://poj.org/problem?id=1110

#include "stdio.h"

char map[80][10][80];
int n;

int main( ) {
int n, r, c, i, j, k, l, test = 0;
while( scanf( "%d%d%d", &n, &r, &c ) == 3 ) {

if( n == 0 )
break;

for( i=0; i<r; i++ ) {
for( k=0; k<n; k++ )
scanf( "%s", map[k][i] );
}

for( k=0; k<n; k++ ) {
for( i=0; i<r*c; i++ ) {
if( map[k][i/c][i%c] != '.' ) {
for( l=0; l<n; l++ )
if( l!=k && map[l][i/c][i%c] != '.' )
break;
if( l == n )
break;
}
}
if( i < r*c )
map[k][i/c][i%c] = '#';
else {
for( i=0; i<r*c; i++ ) {
if( map[k][i/c][i%c] != '.' ) {
for( j=i+1; j<r*c; j++ ) {
if( map[k][j/c][j%c] != '.' ) {
for( l=0; l<n; l++ )
if( l!=k && map[l][i/c][i%c] != '.' && map[l][j/c][j%c] != '.' )
break;
if( l == n )
goto loop;
} //if
} //for
} //if
}//for
loop:
if( i < r*c )
map[k][i/c][i%c] = '#', map[k][j/c][j%c] = '#';
else
break;
}
}

printf( "Test %dn", ++test );
if( k < n )
printf( "impossiblen" );
else for( i=0; i<r; i++ ) {
for( k=0; k<n; k++ )
printf( "%s%s", k?" ":"", map[k][i] );
printf( "n" );
}
}
return 0;
}
```
This entry was posted in poj. Bookmark the permalink.