i-a Knight ' s Journey
Time limit:1000ms Memory limit:65536kb 64bit IO format:%i64d &%i64u
Submit Status
Description
Background
The Knight is getting bored of seeing, the same black and white squares again and again and have decided to make a Journ EY
around the world. Whenever a knight moves, it is the squares in one direction and one square perpendicular to this. The world of a knight is the chessboard he was living on. Our knight lives in a chessboard that have a smaller area than a regular 8 * 8 board, but it's still rectangular. Can adventurous knight to make travel plans?
problem
Find A path such that the knight visits every square once. The knight can start and end on any square of the board.
Input
The input begins with a positive integer n on the first line. The following lines contain n test cases. Each of the test case consists of a single line with the positive integers p and q, such that 1 <= p * Q <= 26. This represents a p * q chessboard, where p describes how many different square numbers 1, ..., p exist, Q describes Ho W many different square letters exist. These is the first Q letters of the Latin alphabet:a, ...
Output
The output for every scenario begins with a line containing "scenario #i:", where I am the number of the scenario star Ting at 1. Then print a single line containing the lexicographically first path this visits all squares of the chessboard with Knight Moves followed by a empty line. The path should is given on a, the names of the visited squares by concatenating. Each square name is consists of a capital letter followed by a number.
If No such path exist, you should output impossible on a.
Sample Input
31 12 34 3
Sample Output
Scenario #1: A1scenario #2: Impossiblescenario #3: A1B3C1A2B4C2A3B1C3A4B2C4
Haven't read the topic yet ...
I-a Knight ' s Journey