搜索题,

每个状态能扩展出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. 201772020113李清华《面向对象程序设计(java)》第八周学习总结

    实验六 接口的定义与使用 实验时间 2018-10-18 1.实验目的与要求 (1) 掌握接口定义方法: (2) 掌握实现接口类的定义要求: (3) 掌握实现了接口类的使用要求: (4) 掌握程序回调 ...

  2. Fastjson 实体类JSON化过滤字段操作-PropertyFilter

    过滤实体类中年龄等于5的字段 List<Users> models=new ArrayList<>(); for(int i=0;i<11;i++){ Users mod ...

  3. xadmin设置

    1.xadmin配置 INSTALLED_APPS = ( ... 'xadmin' , 'crispy_forms' , 'reversion' , ... ) 2.注册类 import xadmi ...

  4. R语言-图的要素颜色

    1.设置图形要素的颜色 Plot函数中,使用col=参数来决定要素的颜色 如果不指定plot type,颜色加在散点上,如果指定了plot type,例如line,则颜色加在线上 其它函数,例如bar ...

  5. jQuery——检测滚动条是否到达底部

    一.jQuery检测浏览器window滚动条到达底部 jQuery获取位置和尺寸相关函数:$(document).height()    获取整个页面的高度:$(window).height()    ...

  6. 页面JS实现按钮点击增加输入框

    学习记录 https://www.tuicool.com/articles/byUf2qe

  7. 如何用poi生成导出excel

    import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Sheet; import java. ...

  8. poj3273(二分)

    题目链接:https://vjudge.net/problem/POJ-3273 题意:给定n个数,将这n个数划分成m块,问所有块最大值的最小是多少. 思路:注意到所求值最大为109,所以可以用二分来 ...

  9. Python练习-迭代-2018.11.28

    #遍历list L=['a','b','c','d'] l=[] a=0 for n in L: l.insert(a,n) a=a+1 print(l) #遍历dict里的key,导出为list L ...

  10. 347. Top K Frequent Elements 最常用的k个元素

    [抄题]: Given a non-empty array of integers, return the k most frequent elements. For example,Given [1 ...