1. 程式人生 > >LightOJ 1012 Guilty Prince(dfs水題)

LightOJ 1012 Guilty Prince(dfs水題)

Once there was a king named Akbar. He had a son namedShahjahan. For an unforgivable reason the king wanted him to leave the kingdom.Since he loved his son he decided his son would be banished in a new place. Theprince became sad, but he followed his father's will. In the way he found thatthe place was a combination of land and water. Since he didn't know how toswim, he was only able to move on the land. He didn't know how many placesmight be his destination. So, he asked your help.

For simplicity, you can consider the place as a rectangulargrid consisting of some cells. A cell can be a land or can contain water. Eachtime the prince can move to a new cell from his current position if they sharea side.

Now write a program to find the number of cells (unit land)he could reach including the cell he was living.

Input

Input starts with an integer T (≤ 500),denoting the number of test cases.

Each case starts with a line containing two positiveintegersW andH;W and H are the numbers of cellsin thex andy directions, respectively.W andHare not more than 20.

There will be H more lines in the data set, each ofwhich includesW

 characters. Each character represents the status of acell as follows.

1)'.' - land

2)'#' - water

3) '@' - initial position of prince (appears exactlyonce in a dataset)

Output

For each case, print the case number and the number of cellshe can reach from the initial position (including it).

Sample Input

Output for Sample Input

4

6 9

....#.

.....#

......

......

......

......

......

#@...#

.#..#.

11 9

.#.........

.#.#######.

.#.#.....#.

.#.#.###.#.

.#.#[email protected]#.#.

.#.#####.#.

.#.......#.

.#########.

...........

11 6

..#..#..#..

..#..#..#..

..#..#..###

..#..#..#@.

..#..#..#..

..#..#..#..

7 7

..#.#..

..#.#..

###.###

[email protected]

###.###

..#.#..

..#.#..

Case 1: 45

Case 2: 59

Case 3: 6

Case 4: 13

題目大意 : 給個起點,求能夠到達的點的數目

相關推薦

LightOJ 1012 Guilty Princedfs

Once there was a king named Akbar. He had a son namedShahjahan. For an unforgivable reason the king wanted him to leave the kingdom.Since he loved his so

裝箱問題 貪心

細節 3*3 using bsp () include %d main amp 【題目描述】     一個工廠制造的產品形狀都是長方體,它們的高度都是h,長和寬都相等,一共有六個型號,他們的長寬分別為1*1, 2*2, 3*3, 4*4, 5*5, 6*6。這些產品通常使用

7-20 Windows消息隊列 25 分模擬

font aaaaaa include sele str net aaaaa reat iostream 題意: ? 思路: 用優先隊列直接模擬就OK了,另外優先隊列存pair的時候比較的是first的值,實測!! ? 上代碼: 1 #include <ios

codeforces 1060a思維

Let’s call a string a phone number if it has length 11 and fits the pattern “8xxxxxxxxxx”, where each “x” is replaced by a digit. For example, “

【爬山】【hdu薛貓貓001】思維

題目:   Problem Description 小Z準備去爬山,在他的面前有N座山,每座山都有對應的高度。他想選擇兩座高度差最小的山進行攀爬。但由於好多山之間的高度差可能是相同的,所以他需要你告訴他高度差最小的兩座山的高度差是多少以及有多少種不同的選取方式(選取山A、B

7-20 Windows訊息佇列 25 分模擬

題意:  思路: 用優先佇列直接模擬就OK了,另外優先佇列存pair的時候比較的是first的值,實測!! 上程式碼: #include <iostream> #include <queue> #include <cstdio>

codeforces 1060a思維

Let’s call a string a phone number if it has length 11 and fits the pattern “8xxxxxxxxxx”, where each “x” is replaced by a digit. F

【洛谷2264】情書字串

點此看題面 大致題意: 給你nnn個關鍵詞和一個文字串。讓你求出這些單詞在這個文字串中總共出現次數(一句話中同一單詞只算一次)。 細節 這題其實還是比較水的,一道很簡單的TrieTrieTrie題(資

P1067 多項式輸出模擬

題目描述 一元nn次多項式可用如下的表示式表示: 其中,a_ix^iai​xi稱為ii次項,a_iai​ 稱為ii次項的係數。給出一個一元多項式各項的次數和係數,請按照如下規定的格式要求輸出該多項式: 多項式中自變數為xx,從左到右按照次數遞減順序給出多項式。

hdu 5510 Bazinga 字串

題意很簡單:輸入n 然後輸入n個字串,求最大的i, 要求1 ~ i-1 中至少有一個串不是i的子串 思路:直接遍歷就行,兩個for迴圈巢狀(注意,都是自上而下開始),用strstr判斷是不是子串,

P1057 傳球遊戲DP

題目描述 上體育課的時候,小蠻的老師經常帶著同學們一起做遊戲。這次,老師帶著同學們一起做傳球遊戲。 遊戲規則是這樣的:nn個同學站成一個圓圈,其中的一個同學手裡拿著一個球,當老師吹哨子時開始傳球,每個同學可以把球傳給自己左右的兩個同學中的一個(左右任意),當老師再次吹哨子

Alyona and Numbers數學

題意分析:給定兩個數n,m, 1 <=  x <= n,   1 <= y <= m,求一共有多少個有序對(x, y)滿足(x + y) % 5 == 0,題意很簡單,直接上

HDU1251 統計難題map

統計難題 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 56034    Accepted Submissi

hdu 1039 字串

不滿足的標記,純水 #include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { char s[25];

hdu6112模擬

今夕何夕Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1278    Accepted Submission(

Max Sumdp

還是子序列求和 Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 186386    Acc

【poj1048 Parencodings】模擬

連結:http://poj.org/problem?id=1068題意:給出一串陣列:a[i]表示第i個右括號前面有幾個左括號,求出每個右括號所包含的括號數分析:模擬。根據已知的陣列,模擬得到一個字串陣列,再模擬每個右括號的括號數程式碼:#include<cstdio&

What day is that day?zoj

What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input Ther

2019浙大校賽--J--Extended Twin Composite Number毒瘤

img xtend ostream ima () == turn scan long 毒瘤出題人,坑了我們好久,從基本的素數篩選,到埃氏篩法,到隨機數快速素數判定,到費馬小定理,好好的水題做成了數論題。 結果答案是 2*n=n+3*n,特判1,2. 以下為毒瘤題目:

【Gym - 100923A】Por Costel and Azerah思維

Por Costel and Azerah Descriptions 給你n個數 問你,有多少個子序列 的和是偶數  Example Input 233 10 124 2 Output 33 題目連結 https://vjudge.net/probl