magic cube
2024-09-22 14:25:53
搜索题,
每个状态能扩展出12种状态,最多进行5次旋转12^5
要用到iddfs,或者我看到网上其他人用的ida*
我也是参考了别人的代码,而且这个题vj上有点问题,我看数据看了半天,愣是没看明白第二个数据咋回事,后来才知道是vj显示的有问题
#include<iostream>
#include<queue>
#include<cstring>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<string>
using namespace std;
#define ll long long
#define se second
#define fi first
#define oo 0x3fffffff
/*
4
0 1 2 3
5 1 2 3
// 4 5 6
// 7 8 9
//10 11 12 13 14 15 16 17 18 19 20 21
//22 23 24 25 26 27 28 29 30 31 32 33
//34 35 36 37 38 39 40 41 42 43 44 45
// 46 47 48
// 49 50 51
// 52 53 54
*/
int cent[] = {, , , , , };
int face[][] = {
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,},
{,,,,,,,,}
};
int change[][] = {
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,},
{,,,,,,,,,,,,,,,,,,,}
};
char s[];
int a[],b[];
int maxdepth;
int l = ;
bool dfs(int dep);
bool judge();
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
l = ;
for(int i = ;i <= ; ++i)
scanf(" %c",s+i);
//for(int i = 1; i <= 54; ++i)
// printf("%c",s[i]);
for(maxdepth = ;maxdepth <= ; ++maxdepth)
{
if(dfs())
{
if(l == )
{
printf("0\n");break;
}
printf("%d\n", l);
for(int i = ; i < l-; ++i)
{
printf("%d %d ",a[i],b[i]);
}
printf("%d %d\n",a[l-],b[l-]);
break;
}
}
if(maxdepth == )
printf("-1\n");
}
}
bool judge()
{
for(int i = ; i < ; ++i)
{
for(int j = ; j < ; ++j)
{
if(s[face[i][j]] != s[cent[i]])
return false;
}
}
return true;
}
bool dfs(int dep)
{
if(judge())
{
l = dep;
return true;
}
if(dep >= maxdepth)
return false;
char tmp[];
memcpy(tmp,s,sizeof s);
for(int i = ; i < ; ++i)
{
for(int j = ; j < ; ++j)
{
s[change[i][j]] = tmp[change[i^][j]];
}
/*if(dep == 0)
{
for(int i = 0; i < 6; ++i)
for(int j = 0; j < 9; ++j)
printf("%c",s[face[i][j]]);
cout << " " << (i&1) << endl;
cout << endl;
}*/
a[dep] = i/;
b[dep] = i&?-:;
if(dfs(dep+)) return true;
memcpy(s,tmp,sizeof tmp);
}
return false;
}
最新文章
- Atitit 硬件&#160;软件&#160;的开源工作&#160;差异对比
- 洛谷10月月赛Round.3
- Windows Phone 开发环境的搭建
- HTML5文件API
- Model-View-Controller - 杂谈
- Linux系统文件权限&;目录权限
- MEF 编程指南(六):导出和元数据
- AFN演示
- Android 关于屏幕适配
- Linux下,命令 wget 的使用
- 蛋疼的Apple IOS Push通知协议
- LeetCode OJ 292.Nim Gam148. Sort List
- Collector for ArcGIS的使用体验
- mysql笔记一——安装和设置root密码
- sqlserver isnull判断
- C# Ioc ASP.NET MVC Dependency Injection
- Zookeeper的功能以及工作原理 (转自:http://www.cnblogs.com/felixzh/p/5869212.html)
- 最大的k个数问题
- CoUninitialize引发的一个错误
- Linux 进程后台运行的几种方式 screen