码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4801 Pocket Cube

时间:2014-09-26 00:34:37      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

题目链接

去年现场,虎哥1Y的,现在刷刷题,找找状态...

一共6种转法,把3个面放到顶部,左旋和右旋,感觉写的还不错....都写成常数了。

bubuko.com,布布扣
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#define LL long long
using namespace std;
struct node
{
    int num[24];
    int st;
};
int dr[12] = {6,2,10,7,3,0,11,8,4,1,9,5};
int dc[12] = {5,9,1,4,8,11,0,3,7,10,2,6};
int a[12] = {2,3,5,6,7,8,11,12,13,14,16,17};
int b[12] = {12,13,11,16,17,14,10,18,19,15,20,21};
int c[12] = {0,2,22,4,5,6,20,10,11,12,18,16};
int aim[6][4] = {
                {0,1,2,3},
                {4,5,10,11},
                {6,7,12,13},
                {8,9,14,15},
                {16,17,18,19},
                {20,21,22,23}
                };
int judge(int *p)
{
    int ans = 0,i,j;
    for(i = 0;i < 6;i ++)
    {
        for(j = 1;j < 4;j ++)
        {
            if(p[aim[i][j]] != p[aim[i][0]])
            break;
        }
        if(j == 4) ans ++;
    }
    return ans;
}
int main()
{
    node u,v;
    int n,i,ans;
    while(scanf("%d",&n)!=EOF)
    {
        for(i = 0;i < 24;i ++)
        {
            scanf("%d",&u.num[i]);
        }
        u.st = 0;
        queue<node>que;
        que.push(u);
        ans = 0;
        while(!que.empty())
        {
            u = que.front();
            que.pop();
            if(ans == 6) break;
            ans = max(ans,judge(u.num));
            if(u.st == n) continue;
            v.st = u.st + 1;
            //a
            for(i = 0;i < 24;i ++)
            {
                v.num[i] = u.num[i];
            }
            for(i = 0;i < 12;i ++)
            {
                v.num[a[dr[i]]] = u.num[a[i]];
            }
            que.push(v);
            for(i = 0;i < 12;i ++)
            {
                v.num[a[dc[i]]] = u.num[a[i]];
            }
            que.push(v);
            //b
            for(i = 0;i < 24;i ++)
            {
                v.num[i] = u.num[i];
            }
            for(i = 0;i < 12;i ++)
            {
                v.num[b[dr[i]]] = u.num[b[i]];
            }
            que.push(v);
            for(i = 0;i < 12;i ++)
            {
                v.num[b[dc[i]]] = u.num[b[i]];
            }
            que.push(v);
            //c
            for(i = 0;i < 24;i ++)
            {
                v.num[i] = u.num[i];
            }
            for(i = 0;i < 12;i ++)
            {
                v.num[c[dr[i]]] = u.num[c[i]];
            }
            que.push(v);
            for(i = 0;i < 12;i ++)
            {
                v.num[c[dc[i]]] = u.num[c[i]];
            }
            que.push(v);
        }
        printf("%d\n",ans);
    }
    return 0;
}
View Code

 

HDU 4801 Pocket Cube

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/naix-x/p/3993749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!