编程介的小学生 2019-08-19 22:55 采纳率: 20.5%
浏览 168

用C语言解决魔方的问题的解决思路

Problem Description
Following the hype generated by Rubiks Cube Norwegian Open Championship arranged at NTNU this year, each and every student at NTNU has bought such a cube. The professors, however, are dismayed, because the students rather play with their cube instead of listening to the professors lectures.

One professor suddenly gets the idea that if he gives the students a program to solve their cubes they may lose interest in it, so that it will be possible to start teaching again. Of course, the professor don't want to do the grunt work of programming, and you are the lucky assignee of this task.

The professor takes away your cube, locks you in a faraway laboratory and says that you won't get out until you have written a program to solve Rubiks cube.

Luckily, the professor did not specify the size of the cube, so you decide to make the work slightly easier by solving the Rubiks 2 2 2 cube.

Input
The first line of the input consists of a single number T, the number of test cases. Each test case consists of six lines describing the initial configuration of a cube, formatted exactly as in the example input. The characters used for colors are G, R, O, B, Y and W.

Each test case is followed by an empty line.

Output
For each scenario, output a line with the minimum number of moves that is necessecary to solve the cube. A move is turning one face of the cube 90 degrees clockwise or counter-clockwise. (A turn of 180 degrees is considered to be two moves.)

Notes and Constraints
0 < T <= 100
You may assume that all input cubes are scrambled versions of originally solved cubes with six diffierent colors. (Which means there are exactly four occurrences of each color and that it is possible to get the cube to a solved state using moves as described above.)

Sample Input
2
OO
OO
RR GG BB WW
RR GG BB WW
YY
YY
RR
RR
YY OO GG BB
OO GG BB YY
WW
WW

Sample Output
0
1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)