ZOJ 3736 Pocket Cube
来源:互联网 发布:unity3d spine2d插件 编辑:程序博客网 时间:2024/05/01 15:31
模拟。。。就足够了
Pocket Cube is a 3-D combination puzzle. It is a 2 × 2 × 2 cube, which means it is constructed by 8 mini-cubes. For a combination of 2 × 2 mini-cubes which sharing a whole cube face, you can twist it 90 degrees in clockwise or counterclockwise direction, this twist operation is called one twist step.
Considering all faces of mini-cubes, there will be totally 24 faces painted in 6 different colors (Indexed from 0), and there will be exactly 4 faces painted in each kind of color. If 4 mini-cubes' faces of same color rely on same large cube face, we can call the large cube face as a completed face.
Now giving you an color arrangement of all 24 faces from a scrambled Pocket Cube, please tell us the maximum possible number of completed faces in no more thanN twist steps.
Index of each face is shown as below:
Input
There will be several test cases. In each test case, there will be 2 lines. One integer N (1 ≤ N ≤ 7) in the first line, then 24 integers Ci seperated by a sinle space in the second line. For index 0 ≤ i < 24, Ci is color of the corresponding face. We guarantee that the color arrangement is a valid state which can be achieved by doing a finite number of twist steps from an initial cube whose all 6 large cube faces are completed faces.
Output
For each test case, please output the maximum number of completed faces during no more than N twist step(s).
Sample Input
10 0 0 0 1 1 2 2 3 3 1 1 2 2 3 3 4 4 4 4 5 5 5 510 4 0 4 1 1 2 5 3 3 1 1 2 5 3 3 4 0 4 0 5 2 5 2
Sample Output
62
Author: FAN, Yuzhe;CHEN, Cong;GUAN, Yao
Contest: The 2013 ACM-ICPC Asia Changsha Regional Contest
#include <iostream>#include <cstring>#include <cstdio>using namespace std;int mf[24],ans=0;bool _ck(int a,int b,int c,int d){ if(mf[a]==mf[b]&&mf[a]==mf[c]&&mf[a]==mf[d]) return true; return false;}bool ck(){ if(_ck(0,1,2,3)&&_ck(4,5,10,11)&&_ck(6,7,12,13)&&_ck(8,9,14,15)&&_ck(16,17,18,19)&&_ck(20,21,22,23)) return true; return false;}int count_ck(){ return _ck(0,1,2,3)+_ck(4,5,10,11)+_ck(6,7,12,13)+_ck(8,9,14,15)+_ck(16,17,18,19)+_ck(20,21,22,23);}bool zhuan(int a,int b,int c,int d, int e,int f, int g,int h, int i,int j, int k,int l){ ///圈 int t=mf[a]; mf[a]=mf[d];mf[d]=mf[c];mf[c]=mf[b];mf[b]=t; ///环 int t1=mf[e],t2=mf[f]; mf[e]=mf[g];mf[f]=mf[h]; mf[g]=mf[i];mf[h]=mf[j]; mf[i]=mf[k];mf[j]=mf[l]; mf[k]=t1;mf[l]=t2;}void qian1(){ zhuan(13,12,6,7,3,2,5,11,16,17,14,8);}void qian2(){ zhuan(6,12,13,7,2,3,8,14,17,16,11,5);}void zhuo1(){ zhuan(15,14,8,9,1,3,7,13,17,19,21,23);}void zhuo2(){ zhuan(8,14,15,9,23,21,19,17,13,7,3,1);}void shang1(){ zhuan(16,17,19,18,20,21,15,14,13,12,11,10);}void shang2(){ zhuan(16,18,19,17,10,11,12,13,14,15,21,20);}void dfs(int k){ if(ans==6) return ; ans=max(ans,count_ck()); if(!k) return ; qian1(); dfs(k-1); qian2(); qian2(); dfs(k-1); qian1(); zhuo1(); dfs(k-1); zhuo2(); zhuo2(); dfs(k-1); zhuo1(); shang1(); dfs(k-1); shang2(); shang2(); dfs(k-1); shang1();}int main(){ int k;while(scanf("%d",&k)!=EOF){ for(int i=0;i<24;i++) scanf("%d",mf+i); ans=count_ck(); dfs(k); printf("%d\n",ans);} return 0;}
- ZOJ 3736 Pocket Cube
- ZOJ 3736 Pocket Cube
- [dfs] zoj 3736 Pocket Cube
- ZOJ 3736 Pocket Cube 脑补+BFS
- ZOJ 3736 Pocket Cube(暴力,魔方)
- ZOJ 3736——Pocket Cube
- zoj 3726 Pocket Cube(搜索)
- ZOJ 3736 & HDU 4801 - Pocket Cube 打表搜索
- zoj 3736 Pocket Cube(2013亚洲区域赛 长沙站 K)
- Pocket Cube
- Pocket Cube
- hdu 4801 Pocket Cube
- HDU 5292 Pocket Cube
- hdu 5292 Pocket Cube
- hdu 5292 Pocket Cube
- hdu 5292 Pocket Cube
- HDU5983 Pocket Cube 【模拟】
- HDU 5292 Pocket Cube
- 时间序列分析之五:几种建模方法
- 堆排序的本质
- 时间序列分析之六:应用
- http://ranfeng0610.blog.163.com/blog/static/185708284201251524110617/
- 斜杠与反斜杠
- ZOJ 3736 Pocket Cube
- ASM 启动报错 ORA-27300, ORA-27301 and ORA-27302: failure occurred at: sskgpsemsper 解决方法
- ActionBar上添加UI
- 菜鸟学SSH(四)——Struts2拦截器
- JUnit4 学习总结
- java自学笔记之抽象类,接口,对象的多态性,instanceof关键字
- Android adb命令,linux中各种命令
- hdu 2255KM算法模板
- cellpadding与cellspacing的区别