⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfunction.cpp

📁 一个小程序
💻 CPP
字号:
#include<iostream>

using namespace std;

int chess[4][5] = { 0 };
int direction[2][8] = { { -1, -1, -2, -2, 2, 2,  1,  1 },
						{ -2, 2,  1,  -1, 1, -1, 2, -2 } };
//int d[8][2]={{-1,-2},{-1,2},{-2,1},{-2,-1},{2,1},{2,-1},{1,2},{1,-2}};
unsigned long total = 0;

struct Position {
	int row;
	int col;
};

Position start;

//从a开始到起点一共有多少不同的路径
void findWay( Position a ) {
	int i;
	Position here;
	for( i = 0; i < 8; i++ ) {
		here.row = a.row + direction[0][i];
		here.col = a.col + direction[1][i];
		//越界则重新走过另一个方向
		//若不越界且该点没走过
		if( here.row >= 0 && here.row <= 3 && 
			here.col >= 0 && here.col <= 4
			&& chess[here.row][here.col] == 0 ) {
			chess[here.row][here.col] = 1;
			findWay( here );
			chess[here.row][here.col] = 0;
		}
		else {
			if( here.row == start.row && here.col == start.col ) {
				total++;
			}
		}
	}
}

void print() {
	int i, j;
	for( i = 0; i < 4; i++ ) {
		for( j = 0; j < 5; j++ ) {
			cout << chess[i][j] << " ";
		}
		cout << endl;
	}
}

int main() 
{
	cin >> start.row >> start.col;
	chess[start.row][start.col] = 1;
	findWay( start );
	cout << total << endl;
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -