当前位置:网站首页>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;
}
边栏推荐
- Watchful pioneer world outlook Architecture - (how does a good game come from)
- Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
- Solution: vs2017 cannot open the source file stdio h main. H header document [easy to understand]
- 453-atoi函数的实现
- 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
- Notes de lecture sur le code propre
- R language uses econcharts package to create microeconomic or macroeconomic maps, and indifference function to visualize indifference curve
- 股票证券公司排名,有安全保障吗
- Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
- 《代碼整潔之道》讀書筆記
猜你喜欢
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
Yes, that's it!
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
Istio部署:快速上手微服务,
MySQL function
450-深信服面经1
Usage of ieda refactor
IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
SQLite 3.39.0 release supports right external connection and all external connection
KT148A语音芯片ic的硬件设计注意事项
随机推荐
Notes de lecture sur le code propre
R语言使用econocharts包创建微观经济或宏观经济图、indifference函数可视化无差异曲线(indifference curve)
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
安装单机redis详细教程
高并发下如何避免产生重复数据?
2022.7.1-----leetcode. two hundred and forty-one
AcWing 1135. 新年好 题解(最短路+搜索)
ShardingSphere-JDBC5.1.2版本关于SELECT LAST_INSERT_ID()本人发现还是存在路由问题
Detailed tutorial on installing stand-alone redis
PHP asymmetric encryption method private key and public key encryption and decryption method
Data dimensionality reduction principal component analysis
移动机器人路径规划:人工势场法[通俗易懂]
AcWing 181. 回转游戏 题解(搜索—IDA*搜索)
Typescript 之 快速入门
mysql函数
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
How to set priorities in C language? Elaborate on C language priorities
Horizontal ultra vires and vertical ultra vires [easy to understand]
How to print mybats log plug-in using XML file
Getting started with typescript