Pro.ID10162 TitleMagic Squares Title链接http://10.20.2.8/oj/exercise/problem?problem_id=10162 AC22 Submit89 Ratio24.72% 时间&空间限制描述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:
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:
Below is a demonstration of applying the transformations to the initial squares given above:
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:
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:
Below is a demonstration of applying the transformations to the initial squares given above:
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 Source 样例输入2 6 8 4 5 7 3 1 样例输出7 作者 |