8×8 棋盤上有 4 個相同棋子。允許移動:1) 移至相鄰空格(上下左右);2) 跳過相鄰一個棋子落在緊鄰空格(跳棋規則)。給定初始和目標佈局,判斷能否在 ≤8 步內到達。輸入兩行各 8 個整數(4 個棋子的行列坐標),輸出 YES/NO。
int)vis[1<<24] 太大,實際用 unordered_set 或排序數組+二分)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
struct Point { int x, y; bool check() { return x>=0 && x<8 && y>=0 && y<8; } };
struct Node { Point a[5]; int t; } st, ed, e;
int dir[4][2] = {{0,1},{0,-1},{1,0},{-1,0}};
bool vis[16777216+1]; // 狀態標記(視具體編碼範圍調整)
int us[65536+10]; // 正向 BFS 記錄的狀態
int len;
// 狀態編碼:4 個棋子坐標排序後壓縮為整數
int get_hash(Point p[]) { /* 實現編碼邏輯 */ }
// 二分查找正向狀態集合
bool find_state(int hash) { /* 在有序 us 中二分查找 */ }
void dfs() {
// 正向 BFS:從起點擴展 4 步
// 反向 BFS:從終點擴展 4 步,檢查相遇
// 詳見完整代碼...
}
int main() {
while (~scanf("%d%d", &st.a[0].x, &st.a[0].y)) {
// 讀入起點、終點 4 個棋子坐標
// 坐標轉 0-based,調用 dfs()
}
return 0;
}