当前位置:网站首页>AcWing 181. Turnaround game solution (search ida* search)
AcWing 181. Turnaround game solution (search ida* search)
2022-07-02 19:39:00 【Mr. Qiao Da】
AcWing 181. Swing Game
IDA* Search for , The estimated value is f(), Calculate the number with the most eight blocks in the middle 8 It's still a few minutes away , This search does not explicitly limit the number of search layers
/* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 */
#include<bits/stdc++.h>
using namespace std;
const int N = 24;
int q[N];
int oppsite[8] = {
5, 4, 7, 6, 1, 0, 3, 2}; // The opposite operation corresponding to the subscript sequence number
int center[8] = {
6, 7, 8, 11, 12, 15, 16, 17}; // The subscript of the middle eight blocks
int path[N];
int op[8][7] = {
{
0, 2, 6, 11, 15, 20, 22},
{
1, 3, 8, 12, 17, 21, 23},
{
10, 9, 8, 7, 6, 5, 4},
{
19, 18, 17, 16, 15, 14, 13},
{
23, 21, 17, 12, 8, 3, 1},
{
22, 20, 15, 11, 6, 2, 0},
{
13, 14, 15, 16, 17, 18, 19},
{
4, 5, 6, 7, 8, 9, 10}
};
int f(){
// Prediction function , It takes at least a few steps to find the middle circle to be consistent
int state[4] = {
0};
for(int i = 0; i < 8; i ++ ){
state[q[center[i]]] ++ ;
}
int maxv= 0;
for(int i = 1; i <= 3; i ++ ){
maxv = max(maxv, state[i]);
}
return 8 - maxv;
}
void operate(int x){
int t = q[op[x][0]];
for(int i = 0; i < 6; i ++ ){
q[op[x][i]] = q[op[x][i + 1]];
}
q[op[x][6]] = t;
}
bool dfs(int depth, int max_depth, int last){
if(f() + depth > max_depth) return false;
if(!f()) return true;
for(int i = 0; i < 8; i ++ ){
if(last != oppsite[i]){
// One of the pruning , Avoid the reverse operation of the operation just finished
operate(i);
path[depth] = i;
if(dfs(depth + 1, max_depth, i)) return true;
operate(oppsite[i]);
}
}
return false;
}
int main()
{
while(cin>>q[0], q[0]){
for(int i = 1; i < 24; i ++ ) cin>>q[i];
int depth = 0;
while(!dfs(0, depth, -1)) depth ++ ;
if(!depth) printf("No moves needed");
else{
for(int i = 0; i < depth; i ++ ){
printf("%c", 'A' + path[i]);
}
}
cout<<endl<<q[6]<<endl;
}
return 0;
}
边栏推荐
- How to print mybats log plug-in using XML file
- Dictionaries
- Introduction of Ethernet PHY layer chip lan8720a
- MySQL
- Introduction to program ape (XII) -- data storage
- Detailed tutorial on installing stand-alone redis
- Pytorch版本、CUDA版本与显卡驱动版本的对应关系
- AcWing 341. 最优贸易 题解 (最短路、dp)
- Virtual machine initialization script, virtual machine mutual secret key free
- c语言里怎么设立优先级,细说C语言优先级
猜你喜欢

守望先锋世界观架构 ——(一款好的游戏是怎么来的)

高并发下如何避免产生重复数据?

Thread application instance

Introduction to program ape (XII) -- data storage

Dictionaries

基于SSM实现网上购物商城系统

Machine learning notes - time series prediction research: monthly sales of French champagne

定了,就是它!

AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)

Embedded (PLD) series, epf10k50rc240-3n programmable logic device
随机推荐
从20s优化到500ms,我用了这三招
Zabbix5 client installation and configuration
AcWing 1134. Shortest circuit counting problem solution (shortest circuit)
Notes de lecture sur le code propre
《架构整洁之道》读书笔记(下)
AcWing 1128. 信使 题解(最短路—Floyd)
Pytorch版本、CUDA版本与显卡驱动版本的对应关系
Mobile robot path planning: artificial potential field method [easy to understand]
Set up sentinel mode. Reids and redis leave the sentinel cluster from the node
From 20s to 500ms, I used these three methods
Yes, that's it!
Memory management of C
AcWing 1131. Saving Private Ryan (the shortest way)
AcWing 343. Sorting problem solution (Floyd property realizes transitive closure)
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
golang:[]byte转string
4274. 后缀表达式-二叉表达式树
pxe装机「建议收藏」
Watchful pioneer world outlook Architecture - (how does a good game come from)
Detailed tutorial on installing stand-alone redis