当前位置:网站首页>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;
}
边栏推荐
- MySQL table historical data cleaning summary
- AcWing 340. 通信线路 题解(二分+双端队列BFS求最短路)
- Correspondence between pytoch version, CUDA version and graphics card driver version
- Npoi export Excel2007
- 4274. Suffix expression - binary expression tree
- Use cheat engine to modify money, life and stars in Kingdom rush
- Chapter 7 - class foundation
- pxe装机「建议收藏」
- Introduction to mongodb chapter 03 basic concepts of mongodb
- 《重构:改善既有代码的设计》读书笔记(上)
猜你喜欢

安装单机redis详细教程

Introduction to program ape (XII) -- data storage

Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出

注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机

Reading notes of "the way to clean structure" (Part 2)

搭建哨兵模式reids、redis从节点脱离哨兵集群

AcWing 342. 道路与航线 题解 (最短路、拓扑排序)

AcWing 903. 昂贵的聘礼 题解(最短路—建图、dijkstra)

KT148A语音芯片ic的硬件设计注意事项

Chic Lang: completely solve the problem of markdown pictures - no need to upload pictures - no need to network - there is no lack of pictures forwarded to others
随机推荐
4274. 后缀表达式-二叉表达式树
How to set priorities in C language? Elaborate on C language priorities
Implementation of 452 strcpy, strcat, StrCmp, strstr, strchr
Refactoring: improving the design of existing code (Part 2)
IEDA refactor的用法
AcWing 1127. 香甜的黄油 题解(最短路—spfa)
453-atoi函数的实现
pxe装机「建议收藏」
PHP parser badminton reservation applet development requires online system
Advanced performance test series "24. Execute SQL script through JDBC"
程序猿入门攻略(十二)——数据的存储
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
452-strcpy、strcat、strcmp、strstr、strchr的实现
搭建哨兵模式reids、redis从节点脱离哨兵集群
2022.7.1-----leetcode. two hundred and forty-one
从20s优化到500ms,我用了这三招
mysql函数
mysql备份后缀是什么_mysql备份还原
【pytorch学习笔记】Tensor
《架构整洁之道》读书笔记(下)