4 人解决,6 人已尝试。
4 份提交通过,共有 11 份提交。
7.7 EMB 奖励。
单点时限: 2.0 sec
内存限制: 256 MB
Flip game is played on a rectangular nm field with two-sided pieces placed on each of its nm squares. One side of each piece is white and the other one is black and each piece is lying either it’s black or white side up. Each round you flip 3 to 5 pieces, thus changing the color of their upper side from black to white and vice versa. The pieces to be flipped are chosen every round according to the following rules:
Choose any one of the pieces.
Flip the chosen piece and also all adjacent pieces to the left, to the right, to the top, to the bottom,to the top left,to the top right,to the bottom left and to the bottom right of the chosen piece (if there are any).
Consider the following position as an example:
…
…
…
Here “.” denotes pieces lying their black side up and “*” denotes pieces lying their white side up. If we choose to flip the 3st piece from the 3rd row (this choice is shown at the picture), then the field will become:
The goal of the game is to flip all pieces white side up. You are to write a program that will search for the minimum number of rounds needed to achieve this goal.
There are many test cases!In each case,the first line are two interger n and m(1<=n,m<=8),and then n lines,each line contain m characters to describle a n*m rectangular field.
Each line output a minimum number of touches required to achieve this goal, or return -1 if it is impossible.
5 5 ***** *...* *...* *...* ***** 3 3 **. **. ... 4 4 *... **.. ..** ...*
1 2 10
4 人解决,6 人已尝试。
4 份提交通过,共有 11 份提交。
7.7 EMB 奖励。
创建: 16 年,6 月前.
修改: 7 年,2 月前.
最后提交: 1 年,4 月前.
来源: N/A