|
||||||||||
24 PuzzleTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 1772 Accepted Submission(s): 572 Problem Description Daniel likes to play a special board game, called 24 puzzle. 24 puzzle is such a game that there are tiles with the number 1 to 23 in a play board like the follow picture: The ¡®#¡¯ denotes the positions that the tiles may be placed on. There are 24 possible positions in total, so one of them is not occupied by the tile. We can denote the empty position by zero. Daniel could move the tiles to the empty position if the tile is on the top, bottom, left or right of the empty position. In this way Daniel can reorder the tiles on the board. Usually he plays with this game by setting up a target states initially, and then trying to do a series of moves to achieve the target. Soon he finds that not all target states could be achieved. He asks for your help, to determine whether he has set up an impossible target or not. Input The first line of input contains an integer denoting the number of test cases. For each test case, the first line contains 24 integers denoting the initial states of the game board. The numbers are the describing the tiles from top to bottom, left to right. And the empty position is indicated by zero. You can assume that the number of each tile are different, and there must be exactly one empty position. The second line of test case also contains 24 integers denoting the target states. Output For each test case, if the target is impossible to achieve, output ¡®Y¡¯ in a single line, otherwise, output ¡®N¡¯. Sample Input
Sample Output
Source | ||||||||||
|