hdu HDU5012-Dice(BFS)

152 篇文章 0 订阅
46 篇文章 0 订阅

题意:

给出旋转方向,询问何时数字可以重合

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
int a[10];
int b[10];
struct node{
    int top,bottom,left,right,ft,bk;
    int step;
    node(int _top,int _bottom,int _left,int _right,int _ft,int _bk,int _step)
    {
        top=_top;
        bottom=_bottom;
        left=_left;
        right=_right;
        ft=_ft;
        bk=_bk;
        step=_step;
    }
};
int vis[7][7][7][7][7][7];
bool flag(node x)
{
    if(vis[x.top ][ x.bottom ][ x.left ][ x.right ][ x.ft ][ x.bk])
        return false;
    vis[x.top ][ x.bottom ][ x.left ][ x.right ][ x.ft ][ x.bk]=1;
        return true;
}
bool judge(node x)
{

    if( x.top==b[1]&&x.bottom==b[2]&&x.left==b[3]&&x.right==b[4]&&x.ft==b[5]&&x.bk==b[6] )
        return true;
    return false;
}
int bfs()
{
    queue<node> q;
    node tmp=node(a[1],a[2],a[3],a[4],a[5],a[6],0);
    q.push(tmp);
    flag(tmp);
    while(!q.empty())
    {
        node tp=q.front();
        q.pop();
        if(judge(tp))
        {
            return tp.step;
        }
        tmp=tp;
        tmp.step++;
        tmp.top=tp.right;
        tmp.bottom=tp.left;
        tmp.left=tp.top;
        tmp.right=tp.bottom;
        if(flag(tmp))
            q.push(tmp);
            
            
        tmp=tp;
        tmp.step++;
        tmp.top=tp.left;
        tmp.bottom=tp.right;
        tmp.left=tp.bottom;
        tmp.right=tp.top;
        if(flag(tmp))
            q.push(tmp);
            
            
        tmp=tp;
        tmp.step++;
        tmp.top=tp.bk;
        tmp.bottom=tp.ft;
        tmp.ft=tp.top;
        tmp.bk=tp.bottom;
        if(flag(tmp))
            q.push(tmp);
            
            
        tmp=tp;
        tmp.step++;
        tmp.top=tp.ft;
        tmp.bottom=tp.bk;
        tmp.ft=tp.bottom;
        tmp.bk=tp.top;
        if(flag(tmp))
            q.push(tmp);
            
    }
    return -1;
}
int main(){
    while(~scanf("%d%d%d%d%d%d",a+1,a+2,a+3,a+4,a+5,a+6))
    {
        memset(vis,0,sizeof(vis));
        for(int i=1;i<=6;i++)
            scanf("%d",&b[i]);
        printf("%d\n",bfs());
    }
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值