A Knight's Journey

A Knight‘s Journey(小白友好详解) A Knight's Journey 有AC代码 阅读详情
A - A Knight's Journey
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Background 
The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey 
around the world. Whenever a knight moves, it is two squares in one direction and one square perpendicular to this. The world of a knight is the chessboard he is living on. Our knight lives on a chessboard that has a smaller area than a regular 8 * 8 board, but it is still rectangular. Can you help this 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 in the first line. The following lines contain n test cases. Each test case consists of a single line with two 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 how many different square letters exist. These are the first q letters of the Latin alphabet: A, . . .

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the lexicographically first path that visits all squares of the chessboard with knight moves followed by an empty line. The path should be given on a single line by concatenating the names of the visited squares. Each square name consists of a capital letter followed by a number. 
If no such path exist, you should output impossible on a single line.

Sample Input

3
1 1
2 3
4 3

Sample Output

Scenario #1:
A1

Scenario #2:
impossible

Scenario #3:
A1B3C1A2B4C2A3B1C3A4B2C4


POJ2488-A Knight's Journey【骑士游历】 北大POJ2488-A Knight's Journey 解题报告+AC代码 立即下载

相关推荐

骑士的旅行

Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is two squares in one...

u013345179的博客 578

POJ2488 骑士游历 A Knight's Journey 解题报告

这个题有3点要注意的地方。 1、弄清题意,p指行号,从上到下依次是1,2,3...p;q指列号,从左到右依次是A,B,C,D...,字典序输出意思是先按列排序,左边的在前,同一列的按行排序,行号小的在前。 2、递归遇到某个方块的下一步无处可跳时,返回上层之前要把vis矩阵相应位置清零!还有起始位置就是A1,如果A1无解则不需要再遍历别的情况了,直接输出impossible即可。 3、输出的时

monkeyduck的专栏 1413

【POJ 2488】A Knight‘s Journey 题解(深度优先搜索)

骑士厌倦了一次又一次地看到同样的黑白方块,决定去旅行全世界每当骑士移动时,它是一个方向上的两个正方形和一个垂直于这个方向的正方形。骑士的世界就是他生活的棋盘。我们的骑士生活在一个棋盘上,这个棋盘的面积比普通的8*8棋盘小,但它仍然是矩形的。你能帮助这位冒险的骑士制定旅行计划吗?问题找到一条道路,让骑士访问每个广场一次。骑士可以在棋盘的任何一方开始和结束。输入输入以第一行中的正整数n开始。以下行包含n个测试用例。每个测试用例都由一条包含两个正整数p和q的单行线组成,因此1

HEX9CF的技术博客 970

POJ 2488 A Knight's Journey题解

A Knight's JourneyTime Limit:1000MS    Memory Limit:65536KB    64bit IO Format:%I64d & %I64u SubmitStatusPracticePOJ 2488 Appoint description: Description Background The knight is

SDUTACM的博客 792

A - A Knight's Journey

Description 整天待在方块里的骑士感到特别的无聊,于是他决定来一场说走就走的旅行。 然而他只能走日字,如右图所示,如果骑士当前在棋盘的正中央,他可以走标记有白点的八个区域。 骑士知道世界是一个列数和行数均不超过8(即8×8)的棋盘。 并且骑士有一点强迫症,如果用A-Z来表示列,1-99来表示横行,他只愿意走字典序最小的一条道路。 你能帮助勇敢的骑士制定一个适合他的旅行计划,使得他

坏鱼儿恋夏的博客 1547

HDOJ-三部曲一(搜索、数学)- A Knight's Journey

A Knight's Journey Time Limit : 2000/1000ms (Java/Other)Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 51Accepted Submission(s) : 17 Problem Description Background The knigh...

weixin_30877181的博客 159

POJ 2488 A Knight's Journey

题目链接:https://vjudge.net/problem/POJ-2488 题目大意   多组数据,每组给定一个 p * q 的国际象棋棋盘,问国际象棋中的骑士能否选取一个起点,然后从这个起点能够不重复地走到所有格子,如果有,输出字典序最小的路径。 分析   先说结论,如果这条路存在,那么字典序最小的路径的起点一定是 A1。   这个结论是猜出来的,因为我看很多帖子说的都...

weixin_30346033的博客 133

A Knight's Journey 解题报告

题目大意:              骑士在一个棋盘上走,是否能全部遍历整个棋盘,他是按"日"方式走的.     重点是按字典顺序输出的                                                             解题思路:        dfs+回溯,横行为字母,纵行为数字。 #include #include #define

小伟的专栏 3052

002:A Knight's Journey

描述 Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it is two squares in o...

欲买桂花同载酒 212

【POJ】A Knight's Journey

Problem hereDescriptionBackgroundThe knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knight moves, it i

Blog 424

1. A Knight's Journey

骑士游历问题 题目链接 Description Background The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey  around the world. Whenever a knight mo...

JCC 332
上一篇: sort函数的用法
下一篇: Sudoku解题报告(陈小宾)
CSUST_ACM
博客等级 码龄15年 42粉丝 127原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值