Rubik's Cube

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5836

Description

As we all know, Zhu is the wisest man. When Liao was ninety-nine years old, the Zhu appeared to him and said, "I am God Almighty; walk before me and be blameless.

I will confirm my covenant between me and you and will greatly increase your wisdom." At that time, Liao has a problem:

Liao has a Rubik's Cube and the surfaces of it are drawn as black or white. He can rotate it as the rules of the Rubik's Cube. Liao asked Zhu:"how many states the Rubik's Cube can reach?"

Zhu is omniscient and omnipotent, but he did not tell the answer. Can you tell the poor man the answer? Remember two states are regarded as the same one if you change views and find the two states is the same one.

For those of you unfamiliar with the puzzle, a Rubik's Cube, comes in the form of a cube where each face is divided into three rows and three columns (nine "squares". Any of the six faces of the cube may be rotated either clockwise or counterclockwise, which also rotates the three nearest squares on each adjoining face onto a new face, respectively.

Input

Intput contains multiple test cases.

The first line is an integer 1≤T≤10, the number of test cases.

Each case begins with an integer n, indicating the number of the squares of blacks.

The next line contains n integers a1,a2,..,an, representing squares indexed as a1,a2,..,an are black respectively. All ai are defferent. The indexes of squares are showed in the pictures. (0≤n≤5,0≤ai≤53).

Output

For each test case,output a single line "Case #x: y", where x is the case number, starting from 1. And y is the answer.

Sample Input

3
2
0 47
2
24 53
2
36 46

Sample Output

Case #1: 15
Case #2: 15
Case #3: 24

Hint

题意

给你一个魔方,告诉你这个魔方有一些格子是黑色的,问你这个魔方旋转之后能够得到多少个不同的魔方。

就是不同的要,完全不同。

就旋转相同,也算相同。

题解:

XJB搜,你需要买一个魔方,然后XJB转一下 ,看看转移是什么样的,当然你有强大的脑补能力也可以……

然后就完了……

代码

//by Atlantis67
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int f[4][54]={{2,5,8,1,4,7,0,3,6,36,37,38,12,13,14,15,16,17,9,10,11,21,22,23,24,25,26,18,19,20,30,31,32,33,34,35,27,28,29,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53},{6,3,0,7,4,1,8,5,2,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,9,10,11,12,13,14,15,16,17,47,50,53,46,49,52,45,48,51},{29,32,35,28,31,34,27,30,33,2,5,8,1,4,7,0,3,6,20,23,26,19,22,25,18,21,24,47,50,53,46,49,52,45,48,51,42,39,36,43,40,37,44,41,38,11,14,17,10,13,16,9,12,15},{18,19,20,21,22,23,24,25,26,11,14,17,10,13,16,9,12,15,45,46,47,48,49,50,51,52,53,33,30,27,34,31,28,35,32,29,8,7,6,5,4,3,2,1,0,44,43,42,41,40,39,38,37,36}};set<LL> s;
LL duilie[10000000];
int tot=0;
void pri(LL a,LL b,int ha)
{printf("================\n");for (int j=0;j<54;j++) if ((a>>j)&1) printf("%d ",j);puts("");for (int j=0;j<54;j++) if ((b>>j)&1) printf("%d ",j);puts("");printf("%d\n",ha);getchar();
}
void BFS(LL first)
{int fron=0,rear=1;duilie[0]=first;s.insert(first);while (fron<rear){LL now=duilie[fron];for (int k=0;k<4;k++){LL next=0;for (int j=0;j<54;j++) {if ((now>>j)&1)next|=(1LL<<f[k][j]);}if (s.find(next)==s.end()) {//pri(now,next,k);duilie[rear++]=next;s.insert(next);}}fron++;}tot=rear;
}
LL w[100];
set<LL> si;
int wtot;
void gao(LL first)
{si.clear();wtot=0;int fron=0,rear=1;w[0]=first;si.insert(first);while (fron<rear){LL now=w[fron];for (int k=1;k<4;k++){LL next=0;for (int j=0;j<54;j++) {if ((now>>j)&1)next|=(1LL<<f[k][j]);}if (si.find(next)==si.end()) {w[rear++]=next;si.insert(next);}}fron++;}wtot=rear;
}
int suan()
{int ans=0;for (int j=0;j<tot;j++){if (s.find(duilie[j])!=s.end()){gao(duilie[j]);for (int k=0;k<wtot;k++) s.erase(w[k]);assert(24%wtot==0);ans++;}}return ans;
}
int main()
{int T;scanf("%d",&T);int t=T;while (T--){int n;scanf("%d",&n);LL first=0;for (int j=0;j<n;j++){int g;scanf("%d",&g);first|=(1LL<<g);}//cout<<first<<endl;s.clear();tot=0;BFS(first);printf("Case #%d: %d\n",t-T,suan());}return 0;
}

HDU 5836 Rubik's Cube BFS相关推荐

  1. 专题训练二 搜索进阶 HDU - 3085 Nightmare Ⅱ (双向BFS + 曼哈顿距离)

    HDU - 3085 Nightmare Ⅱ (双向BFS + 曼哈顿距离) Problem Description Last night, little erriyue had a horrible ...

  2. 算法设计与分析: 5-22 魔方(Rubik's Cube)问题

    5-22 魔方(Rubik's Cube)问题 问题描述 3×3×33×3×33\times3\times3 魔方的构造如图所示.图中英文字母 U,L,F,R,B,D 分别表示魔方的 6 个面中的上面 ...

  3. HDU 1043 Eight(双向BFS+康托展开)

    http://acm.hdu.edu.cn/showproblem.php?pid=1043 题意:给出一个八数码,求出到达指定状态的路径. 思路:路径寻找问题.在这道题里用到的知识点挺多的.第一次用 ...

  4. HDU 5876 关于补图的bfs

    1.HDU 5876  Sparse Graph 2.总结:好题,把STL都过了一遍 题意:n个点组成的完全图,删去m条边,求点s到其余n-1个点的最短距离. 思路:把点分为两个集合,A为所有没有到达 ...

  5. HDU(1175),连连看,BFS

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1175 越学越不会,BFS还是很高级的. 连连看 Time Limit: 20000/100 ...

  6. HDU 1728 逃离迷宫(BFS的优化)

    这一题,有两个地方需要注意:(除了题目令人窒息的行列的x y设置) ①转弯如何判断? 需要给转弯的方向赋值.通常,我们在节点向四个方向延伸的时候,喜欢这样 int nextx[4]={0,0,-1,1 ...

  7. HDU 1495 非常可乐(数论,BFS)

    非常可乐 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  8. 二阶魔方还原 Rubik’s Cube 双向广度优先搜索

    1. 算法简介 使用搜索算法完成二阶魔方从任意初始状态向目标状态的操作转换.         根据已有的研究,二阶魔方的上帝之数为11(进行FTM计数)或14(进行QTM计数),本算法采用QTM计数对 ...

  9. HDU 2612 Find a way bfs

    点击打开链接 Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

最新文章

  1. 「时事点评」我有一个预感,保时捷女车主丈夫要残了!
  2. Razor master page
  3. capitalism 2 3892303_2021年2月5日财神方位查询,今天哪个方位财运好
  4. 【R】语言第五课----画图
  5. 马斯克称新一代Roadster就有望在2023年开始交付
  6. 修改 timezone
  7. 我的javascript学习笔记之数据类型
  8. mysql5.7.9 zip achive
  9. java垃圾回收机制简介
  10. 简明外贸报价单(Price List)范本
  11. java计算机毕业设计教师科研成果管理源码+mysql数据库+系统+lw文档+部署
  12. 虚拟机远程连接USB SERVER
  13. Abaqus6.14+VS2013+IVF2013安装教程
  14. layer常用功能-子页面关闭当前窗口-执行子页面方法-方法回调
  15. Java常用的IO流
  16. java实验常见错误_求高手点拨一个Java SWING的IM系统实验的错误解决方案。
  17. 土木工程考研和计算机考研哪个,土木工程考研还是就业
  18. 最新:基于MAXENT模型的生物多样性生境模拟与保护优先区甄选、自然保护区布局优化评估及论文写作技巧
  19. XC3072锂电池充电IC(耐高压,带OVP,带防反接)
  20. pytorch 12 支持任意维度数据的梯度平衡机制GHM Loss的实现(支持ignore_index、class_weight,支持反向传播训练,支持多分类)

热门文章

  1. 华为服务器面板显示,服务器面板怎么查看
  2. mysql存储过程表_mysql 存储过程,表
  3. oracle insert parallel,insert /*parallel */ 到不同用户,并行起不来的问题
  4. 机械制图手册_42条机械制图基础常识,带徒师傅必备!
  5. jmeter导入已有的脚本_jmeter导入badboy录制的脚本
  6. c 多线程mysql_多线程读写mysql数据库
  7. FPGA设计心得(8)Verilog中的编译预处理语句
  8. Android零基础入门第38节:初识Adapter
  9. 第一章 为什么使用单元测试
  10. CCNP实验:路由重分布注意事项