编程介的小学生 2017-09-18 02:00 采纳率: 20.5%
浏览 733
已采纳

Chess Board

There's an N X M board which filled with black and white chesses.

In each move, the player can flip one of these N X M chesses, meanwhile some chesses of its 8 neighbors will switch into its opposite color(from black to white and from white to black).

Here's four change pattern of the flip operation:

  1. .*.

    • * ('*' denotes the position which will change its color, '.' denotes that the color will stay the same.) .*. It means the chesses of the choosen position's up, down, left and right will switch its color. (Don't forgot the chess which the player choose, it'll also switch its color.)
  2. **.

    • * *.. It means the chesses of its upper-left, up, left, right and bottom-left will switch its color.
  3. .**

    • * .*. It means the chesses of its up, upper-right, left, right and down will switch its color.
  4. .**

    • . .** It means the chesses of its up, upper-right, left, down and bottom-right will switch its color. At the beginning, the player should choose one of these four patterns to flip (the player can only use one pattern in a single game), then try to switch the board into all white. By the way, we want to find a solution with minimal number of operations, if ties, select the smaller index of pattern.

Input

There are multiple test cases (no more than 150).

The first line of each case contains two integer numbers N and M (1 <= N, M <= 15), indicating the width and the height of the board.

The following N lines containing M characters each describe the initial state of the board. '0' and '1' correspond to white and black, respectively.
Input ends with 0 0.

Output

For each test case output the optimal solution, the pattern should be choosen follows by the minimal number of operations.

If none of these four pattern can switch the board into all white, output "Impossible" for the test case.

Sample Input

1 1
1
3 2
11
10
11
5 5
00000
00110
01110
00100
00000
0 0
Sample Output

1 1
4 1
3 1

  • 写回答

1条回答

  • threenewbee 2017-10-02 00:51
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图