10162_MagicSquares

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

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

Pro.ID

10162

Title

Magic Squares

Title链接

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

AC

22

Submit

89

Ratio

24.72%

时间&空间限制

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

    Following the success of the magic cube, Mr. Rubik invented its planar version, called magic squares. This is a sheet composed of 8 equal-sized squares:

    1234
    8765

    In this task we consider the version where each square has a different color. Colors are denoted by the first 8 positive integers. A sheet configuration is given by the sequence of colors obtained by reading the colors of the squares starting at the upper left corner and going in clockwise direction. For instance, the configuration of Figure 3 is given by the sequence (1,2,3,4,5,6,7,8). This configuration is the initial configuration.

    Three basic transformations, identified by the letters 'A', 'B' and 'C', can be applied to a sheet:

    • 'A': exchange the top and bottom row,

    • 'B': single right circular shifting of the rectangle,

    • 'C': single clockwise rotation of the middle four squares.

    Below is a demonstration of applying the transformations to the initial squares given above:

           A:
    8765
    1234
           B:
    4123
    5876
           C:
    1724
    8635

    All possible configurations are available using the three basic transformations.

    You are to write a program that computes a minimal sequence of basic transformations that transforms the initial configuration above to a specific target configuration.

    输入

    Multiple test cases. For each case, a single line with eight space-separated integers (a permutation of (1..8)) that are the target configuration.

    输出

    Description

    Following the success of the magic cube, Mr. Rubik invented its planar version, called magic squares. This is a sheet composed of 8 equal-sized squares:

    1234
    8765

    In this task we consider the version where each square has a different color. Colors are denoted by the first 8 positive integers. A sheet configuration is given by the sequence of colors obtained by reading the colors of the squares starting at the upper left corner and going in clockwise direction. For instance, the configuration of Figure 3 is given by the sequence (1,2,3,4,5,6,7,8). This configuration is the initial configuration.

    Three basic transformations, identified by the letters 'A', 'B' and 'C', can be applied to a sheet:

    • 'A': exchange the top and bottom row,

    • 'B': single right circular shifting of the rectangle,

    • 'C': single clockwise rotation of the middle four squares.

    Below is a demonstration of applying the transformations to the initial squares given above:

           A:
    8765
    1234
           B:
    4123
    5876
           C:
    1724
    8635

    All possible configurations are available using the three basic transformations.

    You are to write a program that computes a minimal sequence of basic transformations that transforms the initial configuration above to a specific target configuration.

    Input

    Multiple test cases. For each case, a single line with eight space-separated integers (a permutation of (1..8)) that are the target configuration.

    Output

    For each case, output :

    Line 1:    A single integer that is the length of the shortest transformation sequence.

    Line 2:    The lexically earliest string of transformations expressed as a string of characters, 60 per line except possibly the last line.

    Sample Input

    2 6 8 4 5 7 3 1

    Sample Output

    7
    BCABCCB

    Source

    样例输入

    2 6 8 4 5 7 3 1

    样例输出

    7
    BCABCCB

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部