UVA 810 A Dicey Promblem 筛子难题 (暴力BFS+状态处理)
读懂题意以后还很容易做的,
和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+状态处理)的更多相关文章
- UVA 810 - A Dicey Problem(BFS)
UVA 810 - A Dicey Problem 题目链接 题意:一个骰子,给你顶面和前面.在一个起点,每次能移动到周围4格,为-1,或顶面和该位置数字一样,那么问题来了,骰子能不能走一圈回到原地, ...
- Uva - 810 - A Dicey Problem
根据状态进行bfs,手动打表维护骰子滚动. AC代码: #include <iostream> #include <cstdio> #include <cstdlib&g ...
- 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 ...
- hdu 1195:Open the Lock(暴力BFS广搜)
Open the Lock Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- A Dicey Problem 骰子难题(Uva 810)
题目描述:https://uva.onlinejudge.org/external/8/810.pdf 把一个骰子放在一个M x N的地图上,让他按照规定滚动,求滚回原点的最短路径. 思路: 记忆化 ...
- zzuli Camellia的难题(暴力)
1784: Camellia的难题 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 67 Solved: 14SubmitStatusWeb Boar ...
- UVa 12325 Zombie's Treasure Chest【暴力】
题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 #include<iostream> #inclu ...
- UVa 11461 - Square Numbers【数学,暴力】
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 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 ...
随机推荐
- 2010辽宁省赛G(佩尔方程)
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...
- AcDbDictionary of AcDbDatabase
GroupDictionary MLStyleDictionary LayoutDictionary PlotStyleNameDictionary MaterialDictionary Visual ...
- 剑指Offer的学习笔记(C#篇)-- 对称的二叉树
题目描述 请实现一个函数,用来判断一颗二叉树是不是对称的.注意,如果一个二叉树同此二叉树的镜像是同样的,定义其为对称的. 一 . 题目分析 递归法. 一.空树判断,单独搞出来. 二.非空树. 递归:一 ...
- 利用sizeof,得到二维数组的维度
#include <iostream> #include <stdlib.h> using namespace std; int main() { ][]; cout < ...
- 如何使用在Windows 下AspNetCore Api 和 consul
在Windows 下如何使用 AspNetCore Api 和 consul https://blog.csdn.net/sD7O95O/article/details/80750803 一.概念:什 ...
- Net Core 分布式微服务框架
Jimu : .Net Core 分布式微服务框架介绍 https://www.cnblogs.com/grissom007/p/9291345.html 一.前言 近些年一直浸淫在 .Net 平台做 ...
- windows/Linux下设置ASP.Net Core开发环境并部署应用
10分钟学会在windows/Linux下设置ASP.Net Core开发环境并部署应用 创建和开发ASP.NET Core应用可以有二种方式:最简单的方式是通过Visual Studio 2017 ...
- 关于FutureTask的探索
之前关于Java线程的时候,都是通过实现Runnable接口或者是实现Callable接口,前者交给Thread去run,后者submit到一个ExecutorService去执行. 然后知道了还有个 ...
- ms sqlserver 清除数据库日志脚本
USE [master] GO ALTER DATABASE F360DW SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE F360DW SET ...
- 持续集成~Jenkins构建dotnetCore的项目
上周一个大件就是dotnet core2.0发布了,伴随着.NET Standard2.0也发布了,整个微软的生态环境大好,当然也有一个BUG出来了,比如EFCore对Mysql的支持比起1.1来说, ...