练习系统 实验四 red and black
| 當(dāng)前編程題:實驗四 基礎(chǔ)算法問題(16級)---Red and Black |
| 1. | 問題描述 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) The end of the input is indicated by a line consisting of two zeros. 輸出形式 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 ....#. .....# ...... ...... ...... ...... ...... #@...# .#..#. 0 0 樣例輸出 45 中文翻譯: 問題描述 有一個長方形的房間,用方瓷磚覆蓋地面。瓷磚的顏色是紅色或黑色。一個人站在一個黑色的瓷磚上。從一個瓷磚可以移動到相鄰的四個瓷磚上。但他不能移動到紅色瓷磚上,他僅可以在黑色的瓷磚上移動。 編寫一個程序來計算他可以到達的黑瓷磚數(shù)量。 輸入形式 輸入由多組數(shù)據(jù)組成。一組數(shù)據(jù)由一個包含兩個正整數(shù)W和H開始;W和H分別是在x和y方向的瓷磚數(shù)。W和H不超過20。 有H行的數(shù)據(jù),其中每行包括W個字符。每個字符代表一個瓷磚的顏色。 '.' -?黑色瓷磚 '#' -?紅色瓷磚 '@' -黑色瓷磚的一個人(在數(shù)據(jù)中只出現(xiàn)一次) 輸入結(jié)束:?由兩個零組成的數(shù)表示。 輸出形式 ??????? 對于每組數(shù)據(jù),你的程序應(yīng)該輸出一行,包含了從最初的瓷磚開始可以達到的瓷磚數(shù)量(包括最初的瓷磚)。
|
總結(jié)
以上是生活随笔為你收集整理的练习系统 实验四 red and black的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OpenVINO2022.1+open_
- 下一篇: 苹果手机 jquery点击无效