10125_CheckerChallenge

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

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

Pro.ID

10125

Title

Checker Challenge

Title链接

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

AC

43

Submit

141

Ratio

30.50%

时间&空间限制

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

    Examine the 6×6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more than one in any diagonal. (Diagonals run from southeast to northwest and southwest to northeast and include all diagonals, not just the major two.)

             Column
    1   2   3   4   5   6
     -------------------------
    1 |   | O |   |   |   |   |
     -------------------------
    2 |   |   |   | O |   |   |
     -------------------------
    3 |   |   |   |   |   | O |
     -------------------------
    4 | O |   |   |   |   |   |
     -------------------------
    5 |   |   | O |   |   |   |
     -------------------------
    6 |   |   |   |   | O |   |
     -------------------------

    The solution shown above is described by the sequence 2 4 6 1 3 5, which gives the column positions of the checkers for each row from 1 to 6:

      ROW  1  2  3  4  5  6
    COLUMN 2  4  6  1  3  5

    This is one solution to the checker challenge.

    Write a program that finds all unique solution sequences to the Checker Challenge (with ever growing values of N). Print the solutions using the column notation described above. Print the the first three solutions in numerical order, as if the checker positions form the digits of a large number, and then a line with the total number of solutions.

    Special note: the larger values of N require your program to be especially efficient. Do not precalculate the value and print it (or even find a formula for it); that's cheating. Work on your program until it can solve the problem properly.

    输入

    Multiple test cases. Each case has a single line that contains a single integer N ( 6 ≤ N ≤ 13 ) that is the dimension of the N × N checkerboard.

    输出

    Description

    Examine the 6×6 checkerboard below and note that the six checkers are arranged on the board so that one and only one is placed in each row and each column, and there is never more than one in any diagonal. (Diagonals run from southeast to northwest and southwest to northeast and include all diagonals, not just the major two.)

             Column
    1   2   3   4   5   6
     -------------------------
    1 |   | O |   |   |   |   |
     -------------------------
    2 |   |   |   | O |   |   |
     -------------------------
    3 |   |   |   |   |   | O |
     -------------------------
    4 | O |   |   |   |   |   |
     -------------------------
    5 |   |   | O |   |   |   |
     -------------------------
    6 |   |   |   |   | O |   |
     -------------------------

    The solution shown above is described by the sequence 2 4 6 1 3 5, which gives the column positions of the checkers for each row from 1 to 6:

      ROW  1  2  3  4  5  6
    COLUMN 2  4  6  1  3  5

    This is one solution to the checker challenge.

    Write a program that finds all unique solution sequences to the Checker Challenge (with ever growing values of N). Print the solutions using the column notation described above. Print the the first three solutions in numerical order, as if the checker positions form the digits of a large number, and then a line with the total number of solutions.

    Special note: the larger values of N require your program to be especially efficient. Do not precalculate the value and print it (or even find a formula for it); that's cheating. Work on your program until it can solve the problem properly.

    Input

    Multiple test cases. Each case has a single line that contains a single integer N ( 6 ≤ N ≤ 13 ) that is the dimension of the N × N checkerboard.

    Output

    For each test case: the first three lines show the first three solutions found, presented as N numbers with a single space between them. The fourth line shows the total number of solutions found.

    Sample Input

    6

    Sample Output

    2 4 6 1 3 5
    3 6 2 5 1 4
    4 1 5 2 6 3
    4

    Source

    样例输入

    6

    样例输出

    2 4 6 1 3 5
    3 6 2 5 1 4
    4 1 5 2 6 3
    4

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部