ZOJ - 3736 Pocket Cube (模拟暴搜)

Pocket Cube

 

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 Ntwist 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

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

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3736

题目大意:一个二阶魔方,按展开图中顺序给每一格的颜色,可以转n次,问在n次内,最大能转出的相同颜色的面是多少

思路:因为上层正着转就相当于是下层逆着转,所以一共只有6种转发,下正,下逆,左正,左逆,前正,前逆。

把6种转法列出来后,因为n<=7,所以爆搜的复杂度为6^7,时间够所以可以直接爆搜。

搜索很简单,但是6种转法列了好久,还总是出错,真的找错找到要当场去世

代码:

#include<stdio.h>
#include<string.h>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
#define ll long long
int ans;
int p[6][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},
                {20,1,22,3,10,4,0,7,8,9,11,5,2,13,14,15,6,17,12,19,16,21,18,23},
                {6,1,12,3,5,11,16,7,8,9,4,10,18,13,14,15,20,17,22,19,0,21,2,23},
                {0,1,2,3,4,5,6,7,8,9,12,13,14,15,21,20,17,19,16,18,11,10,22,23},
                {0,1,2,3,4,5,6,7,8,9,21,20,10,11,12,13,18,16,19,17,15,14,22,23} };

void fun(int b[])
{
    int cnt=0;
    if(b[0]==b[1]&&b[2]==b[3]&&b[0]==b[2]) cnt++;
    if(b[4]==b[5]&&b[10]==b[11]&&b[4]==b[10]) cnt++;
    if(b[6]==b[7]&&b[12]==b[13]&&b[6]==b[12]) cnt++;
    if(b[8]==b[9]&&b[14]==b[15]&&b[8]==b[14]) cnt++;
    if(b[16]==b[17]&&b[18]==b[19]&&b[16]==b[18]) cnt++;
    if(b[20]==b[21]&&b[22]==b[23]&&b[20]==b[22]) cnt++;
    ans=max(ans,cnt);
}
void dfs(int b[],int x)
{
    fun(b);
    if(x==0) return;
    int c[24]={0};
    for(int i=0;i<6;i++)
    {
        for(int j=0;j<24;j++)
            c[j]=b[p[i][j]];
        dfs(c,x-1);
    }
}
int main()
{
    int k,a[24];
    while(~scanf("%d",&k))
    {
        for(int i=0;i<24;i++)
            scanf("%d",&a[i]);
        ans=0;
        dfs(a,k);
        printf("%d\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值