A fire has broken out on the farm, and the cows are rushing to try and put it out!
The farm is described by a 10×1010×10 grid of characters like this:
.......... .......... .......... ..B....... .......... .....R.... .......... .......... .....L.... ..........
The character 'B' represents the barn, which has just caught on fire. The 'L' character represents a lake, and 'R' represents the location of a large rock.
The cows want to form a "bucket brigade" by placing themselves along a path between the lake and the barn so that they can pass buckets of water along the path to help extinguish the fire. A bucket can move between cows if they are immediately adjacent in the north, south, east, or west directions. The same is true for a cow next to the lake --- the cow can only extract a bucket of water from the lake if she is immediately adjacent to the lake. Similarly, a cow can only throw a bucket of water on the barn if she is immediately adjacent to the barn.
Please help determine the minimum number of '.' squares that should be occupied by cows to form a successful bucket brigade.
A cow cannot be placed on the square containing the large rock, and the barn and lake are guaranteed not to be immediately adjacent to each-other.
INPUT FORMAT (file buckets.in):
The input file contains 10 rows each with 10 characters, describing the layout of the farm.
OUTPUT FORMAT (file buckets.out):
Output a single integer giving the minimum number of cows needed to form a viable bucket brigade.
SAMPLE INPUT:
.......... .......... .......... ..B....... .......... .....R.... .......... .......... .....L.... ..........
SAMPLE OUTPUT:
7
In this example, here is one possible solution, which involves the optimal number of cows (7):
.......... .......... .......... ..B....... ..C....... ..CC.R.... ...CCC.... .....C.... .....L.... ..........
Problem credits: Brian Dean
中文版
農(nóng)場(chǎng)上起火了,奶牛們正在緊急趕去滅火!
農(nóng)場(chǎng)可以用一個(gè)像這樣的10×1010×10的字符方陣來描述:
.......... .......... .......... ..B....... .......... .....R.... .......... .......... .....L.... ..........
字符'B'表示正著火的牛棚。字符'L'表示一個(gè)湖,而字符'R'表示農(nóng)場(chǎng)上的一塊巨大巖石。
奶牛們想要沿著一條湖到牛棚之間的路徑組成一條“水桶傳遞隊(duì)列”,這樣她們就可以沿著這條路徑傳遞水桶來幫助滅火。當(dāng)兩頭奶牛在東南西北四個(gè)方向上相鄰時(shí)水桶可以在她們之間傳遞。這對(duì)于湖邊的奶牛也是對(duì)的——奶牛只能在緊挨著湖的時(shí)候才能用水桶從湖里取水。類似地,奶牛只能在緊挨著牛棚的時(shí)候才能用水去滅牛棚的火。
請(qǐng)幫助求出奶牛們?yōu)榱私M成這樣的“水桶傳遞隊(duì)列”需要占據(jù)的'.'格子的最小數(shù)量。
奶牛不能站在巖石所在的方格之內(nèi),此外保證牛棚和湖不是相鄰的。
輸入格式(文件名:buckets.in):
輸入包含10行,每行10個(gè)字符,描述這個(gè)農(nóng)場(chǎng)的布局。輸入保證圖案中恰有一個(gè)字符'B'、一個(gè)字符'L'以及一個(gè)字符'R'。
輸出格式(文件名:buckets.out):
輸出一個(gè)整數(shù),為組成一條可行的水桶傳遞隊(duì)列所需要的奶牛的最小數(shù)量。
輸入樣例:
.......... .......... .......... ..B....... .......... .....R.... .......... .......... .....L.... ..........
輸出樣例:
7
在這個(gè)例子中,以下是一個(gè)可行的方案,使用了最小數(shù)量的奶牛(7):
.......... .......... .......... ..B....... ..C....... ..CC.R.... ...CCC.... .....C.... .....L.... ..........
供題:Brian Dean
以上就是關(guān)于【USACO 2019 US Open Contest, Bronze Problem 1 Bucket Brigade】的解答,如需了解學(xué)校/賽事/課程動(dòng)態(tài),可至翰林教育官網(wǎng)獲取更多信息。
往期文章閱讀推薦:
2026 NOAI國際AI奧賽中國站即將開考!賽事地址&日程已出!
2027 USAAIO美國AI奧賽啟動(dòng)報(bào)名!MIT/谷歌/Jane Street集體站臺(tái)!

? 2026. All Rights Reserved. 滬ICP備2023009024號(hào)-1