读懂题意以后还很容易做的,

AbbottsRevenge类似加一个维度,筛子的形态,可以用上方的点数u和前面的点数f来表示,相对的面点数之和为7,可以预先存储u和f的对应右边的点数,点数转化就很容易了。

具体做法看代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = ;
const int maxd = ;
int g[maxn][maxn];
bool vis[maxn][maxn][maxd][maxd]; struct State
{
int x,y,u,f,pre;
}Q[]; int tor[maxd][maxd]; inline void trans(int u,int f,int i,int &nu,int &nf)
{
if(i == ){ nu = f; nf = -u; return; }
if(i == ){ nu = - tor[u][f]; nf = f; return; }
if(i == ){ nu = - f; nf = u ; return; }
nu = tor[u][f]; nf = f;
} vector<int> ans;
void print_ans(int rst){
for(int i = rst ; ~i; i = Q[i].pre){
ans.push_back(i);
}
vector<int>::reverse_iterator ri = ans.rbegin(),ed = ans.rend();
int cnt = ;
for( ed--; ri != ed; ri++,cnt++){
printf("(%d,%d),",Q[*ri].x,Q[*ri].y);
if(!(cnt%)) 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[] = {-,,,};
const int dy[] = {,,,-};
int head,rear;
head = rear = ;
Q[rear].u = su; Q[rear].f = sf; Q[rear].x = sx; Q[rear].y = sy; Q[rear].pre = -;
rear++;
while(head<rear){
State &u = Q[head];
for(int i = ; i < ; i++){
int nx = u.x + dx[i], ny = u.y + dy[i];
if(~g[nx][ny] && u.u != g[nx][ny]) continue;//0也不满足条件
if(nx == sx && ny == sy){
Q[rear].x = nx; Q[rear].y = ny;
Q[rear].pre = head;
ans.clear();
print_ans(rear);
return;
}
int nu,nf;
trans(u.u,u.f,i,nu,nf);
if(vis[nx][ny][nu][nf]) continue;
vis[nx][ny][nu][nf] = true;
Q[rear].u = nu; Q[rear].f = nf; Q[rear].x = nx; Q[rear].y = ny; Q[rear].pre = head;
rear++;
}
head++;
}
printf("No Solution Possible\n");
} int main()
{
// freopen("in.txt","r",stdin);
char str[];
tor[][] = ; tor[][] = ; tor[][] = ; tor[][] = ;
tor[][] = ; tor[][] = ; tor[][] = ; tor[][] = ;
tor[][] = ; tor[][] = ; tor[][] = ; tor[][] = ;
tor[][] = ; tor[][] = ; tor[][] = ; tor[][] = ;
tor[][] = ; tor[][] = ; tor[][] = ; tor[][] = ;
tor[][] = ; tor[][] = ; tor[][] = ; tor[][] = ;
const int bsz = sizeof(bool)*maxn*;
const int isz = sizeof(int)*maxn;
while(~scanf("%s",str)&& strcmp(str,"END")){
printf("%s\n ",str);
int R,C,sx,sy,su,sf;
scanf("%d%d%d%d%d%d",&R,&C,&sx,&sy,&su,&sf);
memset(vis,,bsz*(R+));
for(int i = ; i <= R; i ++){
for(int j = ; j <= C; j++)
scanf("%d",g[i]+j);
}
memset(g[R+],,isz);
for(int i = ; i <= R; i++) g[i][C+] = ;
bfs(sx,sy,su,sf);
}
return ;
}

UVA 810 A Dicey Promblem 筛子难题 (暴力BFS+状态处理)的更多相关文章

  1. UVA 810 - A Dicey Problem(BFS)

    UVA 810 - A Dicey Problem 题目链接 题意:一个骰子,给你顶面和前面.在一个起点,每次能移动到周围4格,为-1,或顶面和该位置数字一样,那么问题来了,骰子能不能走一圈回到原地, ...

  2. Uva - 810 - A Dicey Problem

    根据状态进行bfs,手动打表维护骰子滚动. AC代码: #include <iostream> #include <cstdio> #include <cstdlib&g ...

  3. hdu 4770 13 杭州 现场 A - Lights Against Dudely 暴力 bfs 状态压缩DP 难度:1

    Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money.&quo ...

  4. hdu 1195:Open the Lock(暴力BFS广搜)

    Open the Lock Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. A Dicey Problem 骰子难题(Uva 810)

    题目描述:https://uva.onlinejudge.org/external/8/810.pdf 把一个骰子放在一个M x N的地图上,让他按照规定滚动,求滚回原点的最短路径. 思路:  记忆化 ...

  6. zzuli Camellia的难题(暴力)

    1784: Camellia的难题 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 67  Solved: 14SubmitStatusWeb Boar ...

  7. UVa 12325 Zombie's Treasure Chest【暴力】

    题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 #include<iostream> #inclu ...

  8. UVa 11461 - Square Numbers【数学,暴力】

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  9. UVA 10012 How Big Is It?(暴力枚举)

      How Big Is It?  Ian's going to California, and he has to pack his things, including his collection ...

随机推荐

  1. js中的"=="和equals()以及is()三者的区别

    在 javaScript或者jQuery中字符串比较没有equals()方法,要比较两个字符串是否相等可以直接用==或者is()进行判断. 例如: "a"=="a&quo ...

  2. PHP中GD库是做什么用的? PHP GD库介绍11111111

    什么是gd库?    gd库是php处理图形的扩展库,gd库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片. 在网站上GD库通常用来生成缩略图或者用来对图片加水印或者对网站数据 ...

  3. 计蒜课/UCloud 的安全秘钥(hash)

    题目链接:https://nanti.jisuanke.com/t/15768 题意:中文题诶- 思路:直接hash就好了,当时zz了没想到... 代码: #include <iostream& ...

  4. 2014-8-5 NOIP(雾)模拟赛

    皇帝的烦恼(二分答案) Description 经过多年的杀戮,秦皇终于统一了中国.为了抵御外来的侵略,他准备在国土边境安置n名将军.不幸的是这n名将军羽翼渐丰,开始展露他们的狼子野心了.他们拒绝述职 ...

  5. To the max(求最大子矩阵和)

    To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 47985   Accepted: 25387 Desc ...

  6. Ubuntu下安装wine plsql

    在电脑上安装了第二系统Ubuntu,但面临各种Linux不支持的开发软件也是束手无策.比如常用的Eclipse,PlSQl,Oracle,QQ等等,于是,上网查阅各种资料,最终的解决方案还是要依赖于w ...

  7. php输出变量加{}的作用

    之前在输出字符串中有变量如 echo “中间有”; echo $i; echo "变量"; 现在发现一个好方法,把变量用{}括起来 echo "中间有{$i}变量&quo ...

  8. node.js安装与配置

    node.js是一个基于Chrome V8引擎的javascrit运行环境. node.js使用了一个事件驱动.非阻塞式I/O的模型,使其轻量又高级. node.js的包管理器npm,是全球最大的开源 ...

  9. JS高级学习历程-6

    PHP菜鸟学习历程-6 [闭包案例] 1 闭包创建数组 <!DOCTYPE html> <html lang="en"> <head> < ...

  10. IOS在滚动的时候fixed消失

      前段时间,除了apple发布了新的硬件之外,同步还发布了新的操作系统,IOS11,当大家都将注意力聚焦在那个奇怪的刘海该如何适配的时候,笔者的项目在适配IOS11却出现了其他的问题. 众所周知,I ...