The cereal guy's friend Serial Guy likes to watch soap operas. An episode are about-to-start, and he hasn ' t washed his plate yet. But he decided to at least put in under the tap is filled with water. The plate can represented by a parallelepiped k x n x m , that's, it has k layers (th E first layer is the upper one), each of which are a rectangle n x m with empty sq Uares ('. ') and obstacles (' # '). The water can only is present in the empty squares. The tap is positioned above the square ( x , y ) of the first layer, it's guarantee D that this square is empty. Every minute a cubical unit of water falls into the plate. Find out on how many minutes the Serial guy should unglue himself from the soap opera and turn the water off for it don't to Overfill the plate. That's, you should find the moment of time when the plate are absolutely full and are going to being overfilled in the next MO ment.
Note:the water fills all the area within reach (see Sample 4). Water flows in each of the 6 directions, through faces of 1x1x1 cubes.
Input
The first line contains three numbersk,N,m(1≤k,N,m≤10) which is the sizes of the plate. Then followkRectangles consisting of n lines each containing m characters '. ' or ' # ', which represents the ' layers ' of the plate in T The He order from the top to the bottom. The rectangles is separated by empty lines (see the samples). The last line contains x and y (1≤ x ≤ n, 1≤ y ≤ m column. Lines of each layer is numbered from the left to right by the integers from 1 to n, columns of each Laye R is numbered from top to bottom by the integers from 1 to M.
Output
The answer should contain a single number, showing on how many minutes the plate would be filled.
The main idea is to give a hexahedral divided into K-layer, each layer n rows m column, each small cube has '. ' (empty) with the ' # ' (barrier) state, the first layer has an empty position with a faucet, and the current flows in six directions each time (as far as the teammates say, I accept incompetence). Although the topic did not understand very clearly simple BFS is over, although this BFS is not elegant ...
#include<cstdio>
#include<queue>
#include<iostream>
using namespace std;
Struct Nod {
Int x;
Int y;
Int Z;
}
Char node [11] [11] [11]; / / layers, lines, columns
Int main ()
{
Int k, N, m;
while(~scanf("%d%d%d",&k,&n,&m)) {
Int sum=0;
Getchar ();
Getchar ();
for(int i=1;i<=k;i++) {
for(int j=1;j<=n;j++) {
for(int p=1;p<=m;p++) {
scanf("%c",&node[i][j][p]);
}
Getchar ();
}
Getchar ();
}
queue<Nod> q;
int sx,sy,nx,ny,nz;
scanf("%d%d",&sx,&sy);
Nod nod;
Nod.x=sx;
Nod.y=sy;
Nod.z=1;
Q.push (NOD);
Sum++;
node[1][sx][sy]=‘#‘;
while(!q.empty()) {
nx=q.front().x;
ny=q.front().y;
nz=q.front().z;
Q.pop ();
if(ny+1<=m && node[nz][nx][ny+1]==‘.‘) {
nod.x=nx;nod.y=ny+1;nod.z=nz;
Q.push (NOD);
Sum++;
node[nz][nx][ny+1]=‘#‘;
}
if(ny-1>=1 && node[nz][nx][ny-1]==‘.‘) {
nod.x=nx;nod.y=ny-1;nod.z=nz;
Q.push (NOD);
Sum++;
node[nz][nx][ny-1]=‘#‘;
}
if(nx+1<=n && node[nz][nx+1][ny]==‘.‘) {
nod.x=nx+1;nod.y=ny;nod.z=nz;
Q.push (NOD);
Sum++;
node[nz][nx+1][ny]=‘#‘;
}
if(nx-1>=1 && node[nz][nx-1][ny]==‘.‘) {
nod.x=nx-1;nod.y=ny;nod.z=nz;
Q.push (NOD);
Sum++;
node[nz][nx-1][ny]=‘#‘;
}
if(nz-1>=1 && node[nz-1][nx][ny]==‘.‘) {
nod.x=nx;nod.y=ny;nod.z=nz-1;
Q.push (NOD);
Sum++;
node[nz-1][nx][ny]=‘#‘;
}
if(nz+1<=k && node[nz+1][nx][ny]==‘.‘) {
nod.x=nx;nod.y=ny;nod.z=nz+1;
Q.push (NOD);
Sum++;
node[nz+1][nx][ny]=‘#‘;
}
}
cout<<sum<<endl;
}
Return 0;
}
Thigh said too young to write so not elegant, to change very tired ... It's true that for the first time, one more +1wa has been written on a single statement. Waiting for the perfect
CF 60B BFS to be refined