Time Limit: 2000/1000 MS
Memory Limit: 65536/32768 K (Java/Others)
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles.
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.
There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.
'.' - a black tile
'#' - a red tile
'@' - a man on a black tile(appears exactly once in a data set)
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0
45
59
6
13
本题据学长说是板子题(简单到不能再简单的那种),好吧。。。。我不会 )X--X( ,,按着板子套了好久,总算弄懂了。。
翻译就不粘了,以后还是要看懂英文的,毕竟很多题都是英文的,,,,,所以就说一下大意吧!!!!
题的大意:@是你的起始位置, 点是你可以走的,#号是墙不能走,问你你能到走的位置的数目(其中包括你的起始位置@)
解题思路:DFS深搜
#include
#include
#include //memset对数组进行赋初值memset(数组名,所赋的值,数组的长度sizeof(数组名)) strcmp
#include //string
#include //vec
#include //que
#include //sta
#include //set se;
#include
以下这个代码是用scanf("%c",&str[i][j]);来接收的:
int main()
{
int stax, stay;
while(scanf("%d %d", &w, &h) != EOF && (w || h))
{
getchar();//第一次吸收掉输入w,h之后的那个回车键;
// for(int i=0; i
本题所学到的: