当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2805:Pegs

题目描述
Peg games may be played on a variety of boards, but the goal is always the same, to end the game with as few pegs on the board as possible. This is accomplished by making a sequence of moves, where one peg 'jumps' an adjacent peg to the empty space on the opposite side. Pegs which are jumped by other pegs are immediately removed.

Given the starting configuration of a peg board, your program should determine the number of pegs that will remain on the board if the player makes the best possible sequence of moves.

One standard peg board is a 5x5 cross (shown below with periods indicating empty peg holes and pound signs indicating non-playable space). Figure A shows an empty board. Figure B shows a board with five pegs, indicated by lower-case letter os. and Figure C shows the result of an optimal sequence of moves from Figure B's starting position. Note that this ends with 1 peg, the best possible result for any game. Also note that the optimal sequence of moves used to generate Figure C is not unique; there are at least two sets of moves that leave only one peg.

#...#

.....
.....
.....
#...#
#.o.#

..o..
oo.o.
.....
#...#
#...#

.....
...o.
.....
#...#
Figure AFigure BFigure C

Note that not all of the peg boards given to you will be the same shape! They will all be 5x5, and will all have at least one peg, at least one empty cell, and at least four non-playable spaces, but the layout may differ drastically from the above.
输入解释
Input to this problem will begin with a line containing a single integer n indicating the number of boards that require analysis. The following 5n lines contain the boards. Each board has a representation like that in the figure above, with a period (.) representing an empty space, lower case o representing a peg, and # representing a non-playable space.

输出解释
For each board in the input, print the message "The best case ends with Y pegs." where Y is replaced with the number of pegs remaining after an optimal set of jumps.

输入样例
3
#.o.#
..o..
oo.o.
.....
#...#
#...#
o.o.o
....o
...o.
#o..#
#..##
.o..#
ooo.o
.o.o.
#..o#

输出样例
The best case ends with 1 pegs.
The best case ends with 4 pegs.
The best case ends with 2 pegs.


该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 South Central USA 2005

源链接: POJ-2805

最后修改于 2020-10-29T06:44:49+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 128000