这题其实只有一点需要注意,就是国际象棋坐标系的选取。
国际象棋有个特点,标号的时候行为数字1~8,列为字母A~H,行从上到下为纵方向,列从左到右为横方向。不同于一般的坐标系,上个图就明白了:
剩下的就是普通的深搜了。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <climits>
using namespace std;
const int MAXN = 10;
const int INF = INT_MAX;
int p, q;
bool visit[MAXN][MAXN];
int direction[8][2] = {
{-1, -2}, {1, -2}, {-2, -1}, {2, -1}, {-2, 1}, {2, 1}, {-1, 2}, {1, 2}};
bool dfs(int x, int y, int step, string path){
if(step == p*q){
cout << path << endl;
retur