RT,输出和数据完全一样。
#6输入
3 3
2 9
#6标准输出
1
4
(这儿有个换行)
代码如下
#include <cstdio>
#include <queue>
const int N = 27, Dir[2][13] = {{0, 2, 2, 2, 2, 1, 1, -1, -1, -2, -2, -2, -2}, {0, 2, 1, -1, -2, 2, -2, 2, -2, 2, 1, -1, -2}};//这个是移动的方向
int otp[3];
bool used[N][N];
struct points{
int x, y, counter;//x, y坐标和计数
}point[3];
std::queue<points> corder;
void bfs(int id){
register points now;
corder.push(point[id]);
while (!corder.empty()){
now = corder.front();corder.pop();
if (used[now.x][now.y])continue;
used[now.x][now.y] = true;
if (now.x == 1 && now.y == 1)return (void)(otp[id] = now.counter);
for (register int i = 1;i <= 12;i ++)
if (now.x + Dir[0][i] > 23 || now.x + Dir[0][i] < -2 || now.y + Dir[1][i] > 23 || now.y + Dir[1][i] < -2)continue;
else corder.push((points){now.x + Dir[0][i], now.y + Dir[1][i], now.counter + 1});
}
}
int main(){
scanf("%d %d %d %d", &point[1].x, &point[1].y, &point[2].x, &point[2].y);
bfs(1);
while (!corder.empty())corder.pop();
for (register int i = 1;i <= 25;i ++)for (register int j = 1;j <= 25;j ++)used[i][j] = false;
bfs(2);
return !printf("%d\n%d\n", otp[1], otp[2]);
}