【搜索】 HDU 5012 Dice
来源:互联网 发布:数据库decimal类型 编辑:程序博客网 时间:2024/05/29 17:15
无脑搜
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;}
0 0
- 【搜索】 HDU 5012 Dice
- Dice - HDU 5012 搜索
- hdu 5012 Dice(隐式图搜索)
- HDU 5012 Dice (bfs + 记忆化搜索)
- hdu 5012 Dice 记忆化搜索
- HDU 5012 Dice 隐式图的搜索
- 【搜索】 HDOJ 5012 Dice
- hdu 5012 Dice
- HDU 5012 Dice
- hdu 5012 dice
- HDU 5012 Dice
- hdu 5012 Dice
- HDU 5012-Dice(BFS)
- HDU 5012 Dice bfs
- hdu 5012 Dice
- HDU - 5012 Dice BFS
- HDU - 5012 Dice
- HDU 5012 Dice
- 中国玩家利用虚拟币节点技术构建去中心化的P2P影子网络BitNet
- MongoDB 如何使定制电子商务变得简单
- stcmp源码分析
- 解决Win7访问Windows 2003、XP共享慢的问题
- TaskOne YYJ学java
- 【搜索】 HDU 5012 Dice
- 采用链地址法处理冲突构造哈希表
- 3-1 Point类的构造函数(构造函数的重载)
- hdu 4993(简单枚举或者hash)
- hdu5001 dp
- 百度以图搜图API介绍
- GIS 像素和米在转化
- Hadoop集群上使用Lzo压缩
- Android进程间通信方式总结(IPC)