http://acm.timus.ru/problem.aspx?space=1&num=1016
http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=14076
1016. Cube on the Walk
Time Limit: 2.0 second
Memory Limit: 16 MB
A cube placed on some square of a usual chessboard. A cube completely covers one square of the chessboard but not anything more, i.e. size of cube’s edge is equal to the size of square’s edge. The integer number
N (0 ≤
N ≤ 1000) is written on the each side of the cube. However it does not imply that the same number is written on all sides. On the different sides there are might be different numbers. One can move a cube to the next square by rotating it around the common edge of the cube and the square. During this motion the sum of the numbers on the bottom of the cube is calculated (each number is added as much times as it appeared at the bottom of the cube). Your task is to find the route between two given squares with the minimal sum of numbers on the bottom side. The numbers on the bottom at the beginning and at the end of walk are also counted. The start and the end positions are different.
Input
The only line of the input contains the necessary data set (only spaces used as delimiters). First, the start position is given, and then the end position. Each position is composed from the character (from ‘a’ to ‘h’ inclusively, it defines the number of the column on the chessboard) and the digit (from ‘1’ to ‘8’ inclusively, it defines the number of the row). That positions are followed by 6 numbers which are currently written on the near, far, top, right, bottom and left sides of the cube correspondingly.
Output
The only line of the output must contain the minimal sum followed by the optimal route (one of possible routes with minimal sum). The route must be represented by the sequence of cube’s positions during the walk. It begins with the start square and ends with the finish square. All square positions on the chessboard should be given in the same format as in input. Use spaces as delimiters.
Sample
|
前 | 后 | 上 | 右 | 下 | 左 | |
init | 1 | 2 | 3 | 4 | 5 | 6 |
turnleft | 1 | 2 | 4 | 5 | 6 | 3 |
turnright | 1 | 2 | 6 | 3 | 4 | 5 |
turnup | 5 | 3 | 1 | 4 | 2 | 6 |
turndown | 3 | 5 | 2 | 4 | 1 | 6 |
init:x=e[0]<<50|e[1]<<40|e[2]<<30|e[3]<<20|e[4]<<10|e[5]
turnleft: ((x&d1)|(x&d2)|(x&d4)<<10|(x&d5)<<10|(x&d6)<<10|(x&d3)>>30)
turnright:((x&d1)|(x&d2)|(x&d6)<<30|(x&d3)>>10|(x&d4)>>10|(x&d5)>>10)
turnup:((x&d5)<<40|(x&d3)<<10|(x&d1)>>20|(x&d4)|(x&d2)>>30|(x&d6))
turndown:((x&d3)<<20|(x&d5)<<30|(x&d2)>>10|(x&d4)|(x&d1)>>40|(x&d6))
然后就是最短路了
#include
#include
#include
#include
#include
#include