poj-2488 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 one direction and one square perpendicular to this. Th…
POJ 2488 -- A Knight's Journey(骑士游历) 题意: 给出一个国际棋盘的大小,判断马能否不重复的走过所有格,并记录下其中按字典序排列的第一种路径. 经典的“骑士游历”问题 输入:第一行,整数n,接下来是n行,每一行为p和q,p为行数,q为列数,p用1...p编号,q用A...Q编号 马的走法:每步棋先横走或直走一格,然后再往外斜走一格;或者先斜走一格,最后再往外横走或竖走一格(即走"日"字).可以越子,没有中国象棋中的"蹩马腿"限制. 解…
A Knight's Journey Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 66   Accepted Submission(s) : 27 Problem Description Background The knight is getting bored of seeing the same black and white…
A Knight's Journey Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 34633Accepted: 11815 Description BackgroundThe knight is getting bored of seeing the same black and white squares again and again and has decided to make a journeyaround the…
给一个矩形棋盘,每次走日字,问能否不重复的走完棋盘的每个点,并将路径按字典序输出 *解法:按字典序输出路径,因此方向向量的数组按字典序写顺序,dfs+回溯,注意flag退出递归的判断,并且用pre记录路径 #include <iostream> #include <cstdio> #include <cstring> using namespace std; char a[30][30]; int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2};…
题目链接:http://poj.org/problem?id=2488 题意: 在国际象棋的题盘上有一个骑士,骑士只能走“日”,即站在某一个位置,它可以往周围八个满足条件的格子上跳跃,现在给你一个p * q的矩形格子,让你找一个跳跃顺序(起点自选),使得这个顺序恰好经过矩阵的每一个格子,且每一个格子仅经过一次,即找一个符合跳跃条件的序列,遍历整个矩形格子.如果有多个,那么就输出字典序最小的. 思路: 貌似可以利用哈密顿通路来解决,但是感觉有点太麻烦,没怎么细想,感觉还是回溯法比较好.首先题目要求…
题目地址:http://poj.org/problem?id=2488 Sample Input 3 1 1 2 3 4 3 Sample Output Scenario #1: A1 Scenario #2: impossible Scenario #3: A1B3C1A2B4C2A3B1C3A4B2C4 题目:给你一个p*q的棋盘,规则布局参考上图.列用字母表示,行用数字表示.这样一个左上角的节点就是(A,1).骑士的棋子走日字形状,可以从任意节点出发,终点也是任意的.问你能不能遍历所有的位…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45941   Accepted: 15637 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. Whe…
题目:http://poj.org/problem?id=2488 题意: 给出一个国际棋盘的大小,判断马能否不重复的走过所有格,并记录下其中按字典序排列的第一种路径. #include <iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<stack> #include<queue> #include<iomanip> #incl…
补个很久之前的题解.... 题目链接: http://poj.org/problem?id=2488 题意: 马走"日"字,让你为他设计一条道路,走遍所有格,并输出字典序最小的一条. 分析: dfs~~~ 代码: #include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef pair<int, int>pii; const int…
poj-2488 题意:一个人要走遍一个不大于8*8的国际棋盘,他只能走日字,要输出一条字典序最小的路径 题解: (1)题目上说的"The knight can start and end on any square of the board.",是个坑点,其实要走字典序最小只需从A1开始遍历就行,因为从任意一点开始,只要能遍历完整个地图,那么A1也可以: (2)要使字典序最小,那么遍历顺序一定要注意 int dr[8]={-1,1,-2,2,-2,2,-1,1};int dc[8]=…
题意:给一个n×m的棋盘,如果一个骑士可以从任意一个位置出发不重复的走遍棋盘的每个格子就输出字典序最短的路径. 解法:dfs.暴搜n×m次,只是被字典序输出坑了……而且字母是列序号数字是行序号……这两个总弄反……搜索的时候会只要按字典序搜那8个方向就可以了,搜到第一条满足条件的路径就结束. 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #includ…
题目 题意:给出一个国际棋盘的大小 p*q,判断马能否不重复的走过所有格,并记录下其中按字典序排列的第一种路径. 因为要求字典序输出最小,所以按下图是搜索的次序搜素出来的就是最小的. 初始方向数组:int f[2][8]={{-2,-2,-1,-1, 1,1, 2,2},  {-1, 1,-2, 2,-2,2,-1,1}}; #include <iostream> #include <cstdio> #include <cstring> using namespace…
A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29226   Accepted: 10023 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 …
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem? id=2488 ----------------------------------------------------------------------------------------------------------------------------------------------------------…
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. Th…
题目链接:http://poj.org/problem?id=2488 题目解读:首先得弄清楚国际象棋中关于“马走日”的规则,如上图中的马,它的下一步的走法有8中,所以对每一个位置的马,它所能走的8个方向坐标设置为 dir[8][2]= {{-1,-2},{1,-2},{-2,-1},{2,-1},{-2,1},{2,1},{-1,2},{1,2}}; 对于最后一组测试案例4 3 画出图解如下: 解题代码: #include<cstdio> #include<cstring> #i…
题目链接:http://poj.org/problem?id=2488 A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36695   Accepted: 12462 Description Background The knight is getting bored of seeing the same black and white squares again and again…
题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A   (A - Children of the Candy Corn) http://poj.org/problem?id=2488   (A Knight's Journey) (不知道为什么,名字竟然不同哇~~~~还是poj 改名改得好) 题目意思:给出一个p * q 的棋盘,行用阿拉伯数字1,2,...,p-1, p 来表示,列从大写字母'A'开始表示.我这里为了简化…
A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35564 Accepted: 12119 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…
A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28697   Accepted: 9822 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  a…
A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35342   Accepted: 12051 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 …
A Knight's Journey Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 51   Accepted Submission(s) : 17 Problem Description Background The knight is getting bored of seeing the same black and white…
迷宫问题(bfs) POJ - 3984   #include <iostream> #include <queue> #include <stack> #include <cstring> using namespace std; /*广度优先搜索*/ /*将每个未访问过的邻接点进队列,然后出队列,知道到达终点*/ typedef class { public: int x; int y; }coordinate; ][]; //迷宫 ][] = { {…
A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35868   Accepted: 12227 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 ar…
DES:给一个n行m列的棋盘.马以L型走.问能否从某一位置开始走完棋盘上的每个位置.若能继续输出字典序最小的一条路径. 很典型的dfs.搜的时候就按照字典序从小到大的顺序.搜到第一条路径时停止搜索输出路经就好了.感觉dfs很机智.WA了几次都是因为保存答案那里没有回溯..........一开始还以为没搞清楚行和列哪个是用字母表示的.....T_T ....读题很难的..... A Knight's Journey #include<stdio.h> #include<iostream&g…
2015-06-05 问题简述: 有一个 p*q 的棋盘,一个骑士(就是中国象棋里的马)想要走完所有的格子,棋盘横向是 A...Z(其中A开始 p 个),纵向是 1...q. 原题链接:http://acm.tju.edu.cn/toj/showp1702.html 解题思路: DFS:深搜把所有情况都考虑一遍,当骑士走出棋盘或走到原来走过的格子时,旅行失败了:当骑士能一直走下去直到走过的格子数等于 p*q 时,旅行成功. 提交过程中一直有一个问题使这个代码一直WA,最后才发现是 p.q输入反了…
题目传送门 本题知识点:深度优先搜索 + 回溯 + 剪枝 + 字典序 题意是给你一个由 p,q 组成一个矩形的棋盘,让你用马棋在这上面走,是否能一线走完这 p * q 个格子. 关于这条路线是怎么走的,自己动手在纸上模拟一下样例3棋子行走的过程就可以了. 所以这种一线走完的题意可以很清楚地想到是深搜. 我第一次写的时候是没有回溯的,没有回溯的话,就会走回路,提交了一遍WA了,所以这里是不能走回路的,必须要用回溯. 如果都能走到的话,那所走的步数肯定是 p * q,所以这里是判断是否已走完的一个判…
A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 41936   Accepted: 14269 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 ar…
Description Roger Wilco is in charge of the design of a low orbiting space station for the planet Mars. To simplify construction, the station is made up of a series of Airtight Cubical Modules (ACM's), which are connected together once in space. One…