# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13014 | Happy A to B |
|
13391 | Domo the Train Conductor |
|
14015 | Hacker Domo |
|
Description
Let's call a grid 8-puzzle board if the gridsize is 3 x 3 and there is exactly one cell is 'x' and others are '1' or '0'.
In one operation, you can exchange the 'x' cell of a 8-puzzle board with any cell which is adjacent to the 'x' cell. The cell (i, j) is adjacent to the cell (i-1, j), (i, j-1), (i, j+1) and (i+1, j).
Now you need to solve T tasks. In each task, you are given two 8-puzzle boards A, B and one integer K. You need to answer whether it's possible to make A into B in at most K operations.
Let's take an example. In the first task of Sample, you can make A into B in the following 2 operations:
0 x 0 0 0 x 0 0 1
1 0 1 ========> 1 0 1 ========> 1 0 x
0 1 1 0 1 1 0 1 1
exchange (1,3) exchange (2,3)
Input
The first line contains an integer T (1 ≤ T ≤ 10) – the number of tasks you need to solve.
And for each task, first you are given one integer K (0 ≤ K ≤ 9) – the maximum number of operations you can execute. Then you are given A and B. Both of them are in 3 lines of 3 characters. Please refer to Sample Input.
Output
For each task output "Yes" if it's possible to make A into B in K operations. Otherwise output "No". Then print a newline('\n').
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Domo is a train conductor, he wants to adjust the train he's driving.
There are five instructions below with the description:
1. AddFront num
Add a train carriage with the index num in front of the train.
2. AddBack num
Add a train carriage with the index num in back of the train.
3. Delete num
Delete all the train carriages with the index num from the train. (If the train has no any carriage with the index num, do nothing)
4. DeleteFront
Delete the first element of the train. (If the train is empty, do nothing)
5. Swap
Reverse all train carriages. (If the train is empty, do nothing)
For example:
AddFront 5 makes the train [4, 1] become [5, 4, 1].
AddBack 5 makes the train [4, 1] become [4, 1, 5].
Delete 5 makes the train [5, 4, 1, 5, 3] become [4, 1, 3].
DeleteFront make the train [1, 2, 3, 4] become [2, 3, 4].
Swap makes the train [2, 6, 3] become [3, 6, 2].
The train is empty in the beginning. Given a series of instructions, please print the index of train carriages after all instructions are executed.
This is a partial judge problem, you're asked to implement these 5 functions.
If you get a TLE:
Try to use the pointer head and back wisely, which can make the AddFront and AddBack instructions faster!
If you get an MLE:
Remember to free the nodes you've deleted!
Input
The input consists of multiple instructions (1 ≤ number of instructions ≤ 105)
the index of each instruction is a positive integer and not greater than 102.
Output
The output only consists of a line denoting the train carriage indices after all the instructions.
It's guaranteed that the output consists of at least one carriage.
Sample Input Download
Sample Output Download
Partial Judge Code
13391.cPartial Judge Header
13391.hTags
Discuss
Description
Domo is a brilliant dog hacker, he wants to find out the password of your computer.
Your password is a sequence of numbers, generated according to the following rules.
Given the number of N and R, we need to arrange the numbers from 1 to N in a continuous Z pattern, where the side length of Z pattern is R.
Here are examples of Z pattern with length 3, 4, and 5. We need to find out which pattern we need to use first.
Next, sequentially fill the numbers from 1 to N into the Z-pattern, starting from the top-left corner.
For example, the Z pattern seems like below when N = 14 and R = 4.
Finally, output each row from top to bottom.
Here's the password when N = 14 and R = 4.
Help Domo find the password, or he'll start getting angry with you.
Input
The first line consists two number N (1 ≤ N ≤ 104) and R (2 ≤ R ≤ 10)
Output
Output the corresponding password sequence, then print a newline character at the end.