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

建议使用的浏览器:

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

3116:MegaCheckers

题目描述

MegaCheckers is a board game for two players, very similar to the known game of Checkers. The board is rectangular, with N rows and M columns of small squares arranged in an N × M grid. The small squares are alternatingly colored with a light color and a dark color, in the usual standard of a checkers board. The squares of dark color are calls “homes” (note however that, for visualization reasons, the figures below show homes as white squares).

At the beginning of the game, each player has a certain number of pieces, placed in homes closest to the edge of the board the player chooses (the players choose opposite edges). During the game, the pieces can only occupy the homes of the board.

One of the moves of the game is to “capture” an opponent’s piece, jumping over it, diagonally, to an adjacent home beyond the piece, which should be empty. The opponent’s piece is then removed from the board. The three homes involved in the capture (the initial home of your piece, the home that holds the opponent’s piece and the empty home, where your piece will be after the play) must be diagonally aligned and diagonally adjacent, as in the figure below.

Simple captureMultiple capture

In MegaCheckers a piece can capture the opponent’s pieces jumping diagonally forward or backward (note that, in the majority of existent variants of the game of checkers, a piece can only capture opponent pieces jumping forward). You can also trigger a multiple capture, with just one piece, jumping successively to empty homes over opponent pieces. In a multiple capture, your piece can change direction, jumping in one direction and later in another one. You can capture only one piece each jump, but can capture several pieces with successive jumps. You can’t jump over a piece of yours, or jump over the same opponent piece more than once.

The dimensions of the board and a description of the current state of a game are given. It’s your turn to play and you should determine of maximum number of your opponent’s pieces that can be captured in one capture move.

输入解释

The input contains several test cases. The first line of a test case contains two integers N and M indicating respectively the number of rows and the number of columns of the board (3 ≤ N ≤ 20, 3 ≤ M ≤ 20 and N × M ≤ 200). The leftmost square of the board at the edge closest to the player is a home. The second line contains the description of the state of the game. Each description consists of ceiling((N × M) ⁄ 2) integers, separated by a space, corresponding to the homes of the board, which are numbered from 1 to ceiling((N × M) ⁄ 2), from left to right, from the edge closest to the player to the edge closest to his opponent. In the description of the state of the game, ‘1’ represents a home with a piece of yours, and ‘2’ represents a home with a piece of your opponent’s. There are at most floor((N × M) ⁄ 4) pieces of each player on the board. The end of the input is indicated by N = M = 0.

(a)(b)

Figure 1: Numeration of homes on (a) board of dimensions 8 × 8 and on (b) board of dimensions 5 × 3.

输出解释

For each test case, your program should produce one line of output, containing an integer indicating the largest number of pieces of your opponent’s that can be captured in one move.

输入样例
3 3
2 1 2 0 1
5 3
1 0 2 1 0 2 0 0
8 8
2 2 2 2 0 0 0 0 2 2 2 2 0 0 0 0 2 2 2 2 0 0 0 0 2 2 2 2 0 1 0 0
0 0
输出样例
1
2
7

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

源链接: POJ-3116

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

共提交 0

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