Pocket Cube HDU
来源:互联网 发布:专业声场测试软件 编辑:程序博客网 时间:2024/05/16 12:11
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 than N 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 separated by a single 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
1
0 0 0 0 1 1 2 2 3 3 1 1 2 2 3 3 4 4 4 4 5 5 5 5
1
0 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
6
2
直接暴力模拟,最近发现dfs的题都写不出
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>using namespace std;int tran[7][24]={ {0,1,8,14,4,3,7,13,17,9,10,2,6,12,16,15,5,11,18,19,20,21,22,23}, {0,1,11,5,4,16,12,6,2,9,10,17,13,7,3,15,14,8,18,19,20,21,22,23}, {1,3,0,2,23,22,4,5,6,7,10,11,12,13,14,15,16,17,18,19,20,21,9,8}, {2,0,3,1,6,7,8,9,23,22,10,11,12,13,14,15,16,17,18,19,20,21,5,4}, {6,1,12,3,5,11,16,7,8,9,4,10,18,13,14,15,20,17,22,19,0,21,2,23}, {20,1,22,3,10,4,0,7,8,9,11,5,2,13,14,15,6,17,12,19,16,21,18,23}, };int M[24];int ans=0;int n;void dfs(int step,int *a){ int num=0; if(a[4]==a[5]&&a[4]==a[10]&&a[4]==a[11]) num++; if(a[6]==a[13]&&a[6]==a[7]&&a[6]==a[12]) num++; if(a[8]==a[9]&&a[8]==a[14]&&a[8]==a[15]) num++; if(a[0]==a[1]&&a[0]==a[2]&&a[0]==a[3]) num++; if(a[16]==a[17]&&a[16]==a[18]&&a[16]==a[19]) num++; if(a[20]==a[21]&&a[20]==a[23]&&a[20]==a[22]) num++; ans=max(ans,num); if(step==n||ans==6) return ; int m[24]; for(int i=0;i<6;i++) { for(int j=0;j<24;j++) m[j]=a[tran[i][j]]; dfs(step+1,m); }}int main(){ while(scanf("%d",&n)==1) { for(int i=0;i<24;i++) scanf("%d",M+i); ans=0; dfs(0,M); printf("%d\n",ans); } return 0;}
- hdu 4801 Pocket Cube
- HDU 5292 Pocket Cube
- hdu 5292 Pocket Cube
- hdu 5292 Pocket Cube
- hdu 5292 Pocket Cube
- HDU 5292 Pocket Cube
- hdu 5983 Pocket Cube
- HDU 4801 Pocket Cube
- Pocket Cube HDU
- HDU 5983Pocket Cube
- HDU 4801 Pocket Cube BFS
- HDU 4801 Pocket Cube bfs
- [模拟]HDU 5983 Pocket Cube
- hdu 5983 Pocket Cube(模拟)
- 【HDU 5983 Pocket Cube】& 模拟
- HDU 5983 Pocket Cube 模拟
- HDU 5983 Pocket Cube (模拟)
- hdu 4801 Pocket Cube(暴力)
- D3D总结(针对自己的学习)
- RedisTemplate访问Redis数据结构(前言)
- 适配器模式
- 欢迎光临阿里云栖大会SAP展区(C区301)!
- JS-SDK微信分享那些事
- Pocket Cube HDU
- Java基础----刷题集(二)
- 采集rtsp流摄像头到浏览器实时播放方案
- SpringBoot学习-(十四)SpringBoot中建立WebSocket连接(STOMP实现发送消息给指定用户)
- IT管理中的六大效应帮你识人用人
- 忙,可忙不是不能兼顾的理由,弱才是。
- sql语句 不让得出的结果默认排序,让其按照in语句的顺序返回结果
- 在Web工程中加入favicon.ico
- 游戏专项测试究竟怎么测?