您的位置:首页 > 其它

【搜索】 HDU 5012 Dice

2014-09-15 18:33 447 查看
无脑搜

next存下骰子转动 哪个面转到哪个面的四种方向

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <math.h>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#define cler(arr, val)    memset(arr, val, sizeof(arr))
#define IN     freopen ("in.txt" , "r" , stdin);
#define OUT  freopen ("out.txt" , "w" , stdout);
typedef long long  LL;
const int MAXN = 130;//点数的最大值
const int MAXM = 20006;//边数的最大值
const int INF = 1101521204;
const int mod = 10000007;
int star[6],end[6];
bool vis[7][7][7][7][7][7];
int next[4][6]={3,2,0,1,4,5
,2,3,1,0,4,5,5,4,2,3,0,1,4,5,2,3,1,0};
struct node
{
int no[6];
int step;
};
queue<node>q;
int bfs()
{
node fre,rear;
while(!q.empty())
q.pop();
int sum=0;
for(int i=0;i<6;i++) if(star[i]==end[i]) sum++;
if(sum==6) return 0;
fre.step=0;
for(int i=0;i<6;i++) fre.no[i]=star[i];
q.push(fre);
while(!q.empty())
{
fre=q.front();
q.pop();
for(int i=0;i<4;i++)
{
int y[6];
for(int j=0;j<6;j++)
y[j]=fre.no[next[i][j]];
if(!vis[y[0]][y[1]][y[2]][y[3]][y[4]][y[5]])
{
vis[y[0]][y[1]][y[2]][y[3]][y[4]][y[5]]=true;
sum=0;
for(int j=0;j<6;j++) if(y[j]==end[j]) sum++;
if(sum==6)return fre.step+1;
else {
for(int j=0;j<6;j++) rear.no[j]=y[j];
rear.step=fre.step+1;
q.push(rear);
}
}
}
}
return -1;
}
int main()
{
//IN;
while(scanf("%d",&star[0])!=EOF)
{
cler(vis,false);
for(int i=1;i<6;i++)
scanf("%d",&star[i]);
for(int i=0;i<6;i++)
scanf("%d",&end[i]);
printf("%d\n",bfs());
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: