文章
1
粉丝
130
获赞
0
访问
2.6k
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;
struct State {
int x,y;
int count;
State() {
count = 0;
x = 0;
y = 0;
}
};
int moves[8][2] = {{2, 1}, {1, 2}, {-1, 2}, {-2,1}, {-2, -1}, {-1, -2}, {1, -2}};
int main () {
int n,m;
while (scanf("%d%d", &n, &m) != EOF) { // n : y 轴 m : x轴
queue<State> sQueue;
vector<vector<bool>> visited(m, vector<bool>(n, false));
State s;
sQueue.push(s);
bool flag = false;
while (!sQueue.empty()) {
s = sQueue.front();
sQueue.pop();
visited[s.x][s.y] = true;
if (s.count == n * m) {
flag = true;
break;
}
for (int i = 0; i < 8; ++i) {
int nx = moves[i][0] + s.x, ny = moves[i][1] + s.y;
if (nx &...
登录后发布评论
你这个程序1*1的时候有问题