本題的重點在於剪枝。對於2,3,4,5號位置上的數字,只有當游標位於該位置上時才可以改變量字。
所以當該位置上的數字和目標狀態對應位置上的數字不同時,一定不會執行left或right。
狀態的表示用乙個string,最後加上一位表示游標的位置。
**:
#include #include #include #include #include #include #include using namespace std;
struct node
node(string a, int b) : stat(a), step(b) {}
}cur;
node start;
string ed;
mapvis;
queueq;
bool check(string stat)
return true;
}void push(string str)
}int bfs() else nex[6]++;
} push(nex);
// left
nex = cur.stat;
if (pos != 0) else nex[6]--;
} push(nex);
} return -1;
}int main()
POJ 1184 聰明的打字員
簡直難到沒朋友。雙向bfs 剪枝。剪枝策略 對於2 5位置上的數,僅僅有當游標在相應位置時通過swap up。down來改變。那麼當當前位置沒有達到目標狀態時,left和right無意義。好了。僅僅剪掉這裡就過掉了。還有比較炫酷的方法實現列舉720種排列。然後狀壓什麼的。功力不夠全然看不懂。incl...
聰明的打字員
題目描述 阿蘭是某機密部門的打字員,她現在接到乙個任務 需要在一天之內輸入幾百個長度固定為6的密碼。當然,她希望輸入的過程中敲擊鍵盤的總次數越少越好。不幸的是,出於保密的需要,該部門用於輸入密碼的鍵盤是特殊設計的,鍵盤上沒有數字鍵,而只有以下六個鍵 swap0,swap1,up,down,left,...
聰明的打字員
正解太妙了 將6 66位上的數字壓縮成乙個int intin t,然後雙向 bfs bfsbf s 爆搜即可,卡卡常數勉強過去 由於 十分簡單,所以就不 想 打注釋了 include include include include include include using namespace st...