搜索题,

每个状态能扩展出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;
}

magic cube的更多相关文章

  1. ZOJ 2477 Magic Cube(魔方)

    ZOJ 2477 Magic Cube(魔方) Time Limit: 2 Seconds      Memory Limit: 65536 KB This is a very popular gam ...

  2. ZOJ2477 Magic Cube

    题目: This is a very popular game for children. In this game, there's a cube, which consists of 3 * 3 ...

  3. ZOJ 2477 Magic Cube 暴力,模拟 难度:0

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1477 用IDA*可能更好,但是既然时间宽裕数据简单,而且记录状态很麻烦,就直接 ...

  4. 2019杭电多校二 F. Fantastic Magic Cube (FWT)

    大意: 给定$N^3$立方体, 每个单位立方体权值为三个坐标异或, 每次沿坐标轴切一刀, 得分为两半内权值和的乘积, 求切成$n^3$块的最大得分. 可以发现得分与切法无关, 假设每个点权值为$a_i ...

  5. sdutoj 2606 Rubik’s cube

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2606 Rubik’s cube Time Li ...

  6. USACO 3.2 Magic Squares

    Magic SquaresIOI'96 Following the success of the magic cube, Mr. Rubik invented its planar version, ...

  7. 用DirectX实现魔方(一)

    关于魔方 魔方英文名字叫做Rubik's Cube,是由匈牙利建筑学教授和雕塑家Ernő Rubik于1974年发明,最初叫做Magic Cube(这大概也是中文名字的来历吧),1980年Ideal ...

  8. 一位学长的ACM总结(感触颇深)

    发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...

  9. ZOJ - 2477 dfs [kuangbin带你飞]专题二

    注意输入的处理,旋转操作打表.递增枚举可能步数,作为限制方便找到最短路. AC代码:90ms #include<cstdio> #include<cstring> char m ...

随机推荐

  1. django之 使用views.py里面的函数对表进行增删改查 内容(models.py中表的创建、views.py中函数的使用,基于对象的跨表查询)

    models之对于表的创建有以下几种: 一对一:ForeignKey("Author",unique=True),  OneToOneField("Author" ...

  2. [持续交付实践] pipeline使用:语法详解

    一.引言 jenkins pipeline语法的发展如此之快用日新月异来形容也不为过,而目前国内对jenkins pipeline关注的人还非常少,相关的文章更是稀少,唯一看到w3c有篇相关的估计是直 ...

  3. 1816647 - Error "Data file of SAP Note is incomplete" uploading a note in SNOTE

    ymptom When uploading an SAP Note in transaction SNOTE you receive the error "Data file of SAP ...

  4. Mac 笔记本 开发日记

    1.录屏,截图 Mac 自带录屏功能 command +control +o 2.复制当前应用,在启一个当前app窗口 command+n 3.快速回到桌面 command +f3 4.选中文件,复制 ...

  5. txt,csv,json互相转化

    也没啥,记下来怕忘了.说明都在代码里面: 麻蛋,这个着色好难看 import csv import json #从txt变为csv student_txt=[]; with open("st ...

  6. H5地理位置信息、微信摇一摇

    geolocation window.navigator.geolocation 1.getCurrentPosition() // 获取当前的位置信息 2.watchPosition() // 监视 ...

  7. 《深入理解JAVA虚拟机》----------第二章 JAVA内存区域与内存溢出异常,笔记(下)

    2. HotSpot虚拟机对象探秘 2.1 对象的创建 虚拟机遇到一条New指令时,首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引用代表的类是否已被加载.解析和初 ...

  8. centos7下面添加htop工具

    htop下载wget http://sourceforge.net/projects/htop/files/latest/download 解压tar -zxf downloadcd htop-1.0 ...

  9. django + nginx + uwsgi

    server{ listen ; server_name 0.0.0.0; charset utf-; access_log /var/log/nginx/access.log main; locat ...

  10. [leetcode]52. N-Queens II N皇后

    The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...