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

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. 如何在 Swoole 中优雅的实现 MySQL 连接池

    如何在 Swoole 中优雅的实现 MySQL 连接池 一.为什么需要连接池 ? 数据库连接池指的是程序和数据库之间保持一定数量的连接不断开, 并且各个请求的连接可以相互复用, 减少重复连接数据库带来 ...

  2. spring-boot-starter-data-redis学习笔记01

    1.Redis在Unbuntu14开启, 进入安装的src目录: 1.修改redis.conf,因为redis默认是受保护模式. protected-mode yes   (改为no) bind 12 ...

  3. MVC+NHibernate笔记

    Nhibernate 要求model实体类对于lazy="true" ,字段属性前需要加 virtual sqlserver2005和oracle10g的hibernate.cfg ...

  4. C++11/14的新特性——更简洁

      新的字符串表示方式——原生字符串(Raw String Literals) C/C++中提供了字符串,字符串的转义序列,给输出带来了很多不变,如果需要原生义的时候,需要反转义,比较麻烦. C++提 ...

  5. JAVA获取本周 本月 本年 第一天和最后一天

    /** * 日期工具类 */ public class DateUtils { /** * 获取今天 * @return String * */ public static String getTod ...

  6. Git 时光穿梭鸡 撤销修改

    工作区内容修改了, 但是并未add到暂存区, 想 回退到上一个版本 在readme.txt中添加了一行: Git is a distributed version control system. Gi ...

  7. JQ下拉加载更多

    <!DOCTYPE=html> <html> <head> <script src="jquery-1.4.2.min.js" type= ...

  8. 51nod1154(dp)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1154 题意:中文题目诶- 思路:字符串长度不大于5e3,O(n ...

  9. Spring.Net框架学习错误集锦1

    最近IoC框架非常火热,所以就学习了非常流行的IOC框架之一spring.NET,遇到如下问题: Error creating context 'spring.root': Could not loa ...

  10. Net Core2-JWT

    NET Core2 http://www.cnblogs.com/wyt007/category/1130278.html JWT 设计解析及定制 前言 上一节我们讲述的书如何使用jwt token, ...