codeforces 60B Serial Time!
2013-08-07 13:47
148 查看
Serial Time!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 hask 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 nlines
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.
Sample test(s)
input
output
input
output
input
output
input
output
input
output
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 hask 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 nlines
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.
Sample test(s)
input
1 1 1 . 1 1
output
1
input
2 1 1.
#
1 1
output
1
input
2 2 2
.#
##
..
..
1 1
output
5
input
3 2 2 #. ## #. .# .. .. 1 2
output
7
input
3 3 3
.#.
###
##.
.##
###
##.
...
...
...
1 1
output
13
#include<cstdio> int K,N,M,ans; char a[12][12][12]; void dfs(int z,int x,int y) { if(z<0||z>=K||x<0||x>=N||y<0||y>=M||a[z][x][y]=='#') return; ans++; a[z][x][y]='#'; dfs(z,x,y+1); dfs(z,x,y-1); dfs(z,x+1,y); dfs(z,x-1,y); dfs(z+1,x,y); dfs(z-1,x,y); } int main() { int i,j; scanf("%d%d%d",&K,&N,&M); for(i=0;i<K;i++) for(j=0;j<N;j++) scanf("%s",a[i][j]); scanf("%d%d",&i,&j); dfs(0,i-1,j-1); printf("%d\n",ans); return 0; }
相关文章推荐
- Codeforces 451C Predict Outcome of the Game(暴力)
- CodeForces 253D Table with Letters - 2
- CodeForces 518D---概率dp
- CodeForces 39C
- codeforces 148A(Insomnia cure) Java
- codeforces 834 C 思路题
- CodeForces 451 C. Predict Outcome of the Game
- codeforces-580C-Kefa and Park【dfs】
- CodeForces 689B - Mike and Shortcuts
- Codeforces 344C Rational Resistance【思维+贪心】
- Codeforces 439D Devu and his Brother【思维+三分查找】
- Codeforces 884f F. Anti-Palindromize
- Codeforces 451 D. Count Good Substrings
- Codeforces 592D Super M
- CodeForces 342B--模拟+贪心
- CodeForces 140E
- Codeforces 626E Simple Skewness(暴力枚举+二分)
- codeforces 837E 数论
- codeforces 452B 4-point polyline
- codeforces 242A Heads or Tails