标签:
The Cereal Guy‘s friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn‘t washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped k × n × m, that is, it has k layers (the first layer is the upper one), each of which is a rectangle n × m with empty squares (‘.‘) and obstacles (‘#‘). The water can only be present in the empty squares. The tap is positioned above the square (x, y) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.
Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1 × 1 × 1 cubes.
Input
The first line contains three numbers k, n, m (1 ≤ k, n, m ≤ 10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters ‘.‘ or ‘#‘, which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1 ≤ x ≤ n, 1 ≤ y ≤ m) which are the tap‘s coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m.
Output
The answer should contain a single number, showing in how many minutes the plate will be filled.
大意是给出一个六面体分为k层,每层n行m列,每个小立方体有‘.‘(空)与‘#‘(障碍)的状态,第一层某个空的位置有一个水龙头,水流每次往六个方向流动(至于队友说水能往上流我表示接受无能)。虽然题目没理解很清楚简单的bfs就过了,虽然这个bfs很不优雅...
#include<cstdio> #include<queue> #include<iostream> using namespace std; struct Nod { int x; int y; int z; }; char node[11][11][11]; //第几层第几行第几列 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; }
大腿说太年轻写的如此不优雅,要改很累...确实第一次就某条语句多写了一个+1wa了一下。等着完善
标签:
原文地址:http://www.cnblogs.com/LinesYao/p/5451429.html