10050_AnEasyPuz

2022-5-16 18:16| 发布者: Hocassian| 查看: 89| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504484354900-Problem List-采集的数据-后羿采集器.html

Pro.ID

10050

Title

An Easy Puz

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10050

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    Wddpdh find an interesting mini-game in the BBS of WHU, called "An easy PUZ". It's a 6 × 6 chess board and each cell has a number in the range of 0 and 3 ( it can be 0, 1, 2 or 3 ). Each time you can choose a number A(i, j) in i-th row and j-th column, then the number A(i, j) and the numbers around it ( A(i-1, j), A(i+1, j), A(i, j-1), A(i, j+1), sometimes there may just be 2 or 3 numbers.) will minus 1 ( 3 to 2, 2 to 1, 1 to 0, 0 to 3 ).

    You can do it finite times. The goal is to make all numbers become 0. Wddpdh now come up with an extended problem about it. He will give you a number N ( 3 ≤ N ≤ 6 ) indicate the size of the board. You should tell him the minimum steps to reach the goal.

    输入

    The input consists of multiple test cases. For each test case, it contains a positive integer N ( 3 ≤ N ≤ 6 ). N lines follow, each line contains N columns indicating the each number in the chess board.

    输出

    Description

    Wddpdh find an interesting mini-game in the BBS of WHU, called "An easy PUZ". It's a 6 × 6 chess board and each cell has a number in the range of 0 and 3 ( it can be 0, 1, 2 or 3 ). Each time you can choose a number A(i, j) in i-th row and j-th column, then the number A(i, j) and the numbers around it ( A(i-1, j), A(i+1, j), A(i, j-1), A(i, j+1), sometimes there may just be 2 or 3 numbers.) will minus 1 ( 3 to 2, 2 to 1, 1 to 0, 0 to 3 ).

    You can do it finite times. The goal is to make all numbers become 0. Wddpdh now come up with an extended problem about it. He will give you a number N ( 3 ≤ N ≤ 6 ) indicate the size of the board. You should tell him the minimum steps to reach the goal.

    Input

    The input consists of multiple test cases. For each test case, it contains a positive integer N ( 3 ≤ N ≤ 6 ). N lines follow, each line contains N columns indicating the each number in the chess board.

    Output

    For each test case, output minimum steps to reach the goal. If you can't reach the goal, output -1 instead.

    Sample Input

    3
    1 1 0
    1 0 1
    0 1 1
    3
    2 3 1
    2 2 1
    0 1 0

    Sample Output

    2
    3

    样例输入

    3
    1 1 0
    1 0 1
    0 1 1
    3
    2 3 1
    2 2 1
    0 1 0

    样例输出

    2
    3

    提示

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部