hdu 5012 2014西安网络赛

当时手一残,有点小bug,被其他队的先a了。哎。
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<queue>
using namespace std;
int a[7],b[7];
bool visit[7][7][7][7][7][7];

int bfs()
{
    queue<int> q[6];
    queue<int> step;
    int c[6];
    step.push(0);
    for(int i=0; i<6; i++)
    {
        q[i].push(b[i]);
    }
    visit[b[0]][b[1]][b[2]][b[3]][b[4]][b[5]]=true;
    while(!q[1].empty())
    {
        for(int i=0; i<6; i++)
        {
            c[i]=q[i].front();
        }
        int t=step.front();
        bool flag=true;
        for(int i=0; i<6; i++)
        {
            if(c[i]!=a[i])
                flag=false;

        }
        if(flag)
            return t;
        if(!visit[c[3]][c[2]][c[0]][c[1]][c[4]][c[5]]) //left
        {

            step.push(t+1);
            q[0].push(c[3]);
            q[1].push(c[2]);
            q[2].push(c[0]);
            q[3].push(c[1]);
            q[4].push(c[4]);
            q[5].push(c[5]);
            visit[c[3]][c[2]][c[0]][c[1]][c[4]][c[5]]=true;
        }
        // cout<<step.front()<<endl;

        if(!visit[c[2]][c[3]][c[1]][c[0]][c[4]][c[5]]) //right
        {
            step.push(t+1);
            q[0].push(c[2]);
            q[1].push(c[3]);
            q[2].push(c[1]);
            q[3].push(c[0]);
            q[4].push(c[4]);
            q[5].push(c[5]);
            visit[c[2]][c[3]][c[1]][c[0]][c[4]][c[5]]=true;
        }

        //cout<<"2"<<endl;

        if(!visit[c[5]][c[4]][c[2]][c[3]][c[0]][c[1]]) //back
        {
            step.push(t+1);
            q[0].push(c[5]);
            q[1].push(c[4]);
            q[2].push(c[2]);
            q[3].push(c[3]);
            q[4].push(c[0]);
            q[5].push(c[1]);
            visit[c[5]][c[4]][c[2]][c[3]][c[0]][c[1]]=true;
        }

        //cout<<"3"<<endl;

        if(!visit[c[4]][c[5]][c[2]][c[3]][c[1]][c[0]]) //front
        {
            step.push(t+1);
            q[0].push(c[4]);
            q[1].push(c[5]);
            q[2].push(c[2]);
            q[3].push(c[3]);
            q[4].push(c[1]);
            q[5].push(c[0]);
            visit[c[4]][c[5]][c[2]][c[3]][c[1]][c[0]]=true;
        }
        //  cout<<"4"<<endl;

        for(int i=0; i<6; i++)
        {
            q[i].pop();
        }
        step.pop();
    }
    return -1;

}
int main()
{
    while(~scanf("%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5]))
    {
        memset(visit,false,sizeof(visit));
        for(int i=0; i<6; i++)
            scanf("%d",&b[i]);
        int count=0;
        for(int i=0; i<3; i++)// 剪枝
        {
            int a1=a[i*2],a2=a[i*2+1];
            for(int j=0; j<3; j++)
            {
                int b1=b[j*2],b2=b[j*2+1];
                if( (a1==b1&&a2==b2) || (a1==b2)&& (a2==b1) )
                    count++;
            }

        }
        // cout<<count<<endl;
        if(count!=3)
        {
            cout<<"-1"<<endl;
            continue;
        }
        cout<<bfs()<<endl;
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值