读懂题意以后还很容易做的,
和类似加一个维度,筛子的形态,可以用上方的点数u和前面的点数f来表示,相对的面点数之和为7,可以预先存储u和f的对应右边的点数,点数转化就很容易了。
具体做法看代码
#includeusing namespace std;const int maxn = 11;const int maxd = 7;int g[maxn][maxn];bool vis[maxn][maxn][maxd][maxd];struct State{ int x,y,u,f,pre;}Q[6000];int tor[maxd][maxd];inline void trans(int u,int f,int i,int &nu,int &nf){ if(i == 0){ nu = f; nf = 7-u; return; } if(i == 1){ nu = 7 - tor[u][f]; nf = f; return; } if(i == 2){ nu = 7 - f; nf = u ; return; } nu = tor[u][f]; nf = f;}vector ans;void print_ans(int rst){ for(int i = rst ; ~i; i = Q[i].pre){ ans.push_back(i); } vector ::reverse_iterator ri = ans.rbegin(),ed = ans.rend(); int cnt = 1; for( ed--; ri != ed; ri++,cnt++){ printf("(%d,%d),",Q[*ri].x,Q[*ri].y); if(!(cnt%9)) printf("\n "); } printf("(%d,%d)\n",Q[*ed].x,Q[*ed].y);}void bfs(int sx,int sy,int su,int sf){ const int dx[] = {-1,0,1,0}; const int dy[] = { 0,1,0,-1}; int head,rear; head = rear = 0; Q[rear].u = su; Q[rear].f = sf; Q[rear].x = sx; Q[rear].y = sy; Q[rear].pre = -1; rear++; while(head