当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

AcWing 342. Road and route problem solving (shortest path, topological sorting)

《MongoDB入门教程》第03篇 MongoDB基本概念

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

Zabbix5 client installation and configuration

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

Usage of ieda refactor

Advanced performance test series "24. Execute SQL script through JDBC"

安装单机redis详细教程

Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode

Py之interpret:interpret的简介、安装、案例应用之详细攻略
随机推荐
Digital scroll strip animation
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
Gamefi chain game system development (NFT chain game development function) NFT chain game system development (gamefi chain game development source code)
451 implementation of memcpy, memmove and memset
多端小程序开发有什么好处?覆盖百度小程序抖音小程序微信小程序开发,抢占多平台流量红利
IEDA refactor的用法
Data Lake (XII): integration of spark3.1.2 and iceberg0.12.1
Npoi export Excel2007
2022.7.1-----leetcode. two hundred and forty-one
Introduction of Ethernet PHY layer chip lan8720a
Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
AcWing 1135. 新年好 题解(最短路+搜索)
Yes, that's it!
AcWing 1127. 香甜的黄油 题解(最短路—spfa)
Microservice technology - distributed global ID in high concurrency
AcWing 1125. Cattle travel problem solution (shortest path, diameter)
良心总结!Jupyter Notebook 从小白到高手,保姆教程来了!
AcWing 383. 观光 题解(最短路)
Thread application instance
字典