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 ...
随机推荐
- API---CreateIoCompletionPort
HANDLE WINAPI CreateIoCompletionPort( __in HANDLE FileHandle, __in HANDLE Existi ...
- 洛谷P5173 传球(暴力)
传送门 真·暴力艹过去 不难发现这个转移其实就是一个循环卷积的形式,设有多项式\(A=x+x^{n-1}\),那么\(f_m=f_0\times A^m\) 直接暴力计算并卡常就行了 //minamo ...
- cinder存储服务
一.cinder 介绍: 理解 Block Storage 操作系统获得存储空间的方式一般有两种: 1.通过某种协议(SAS,SCSI,SAN,iSCSI 等)挂接裸硬盘,然后分区.格式化.创建文件系 ...
- nginx 第二课
基本配置格式 Nginx全局配置参数 使用include文件 HTTP的server部分 虚拟服务器部分 location —— where,when,how. mail的server部分. 完整的示 ...
- 牛客练习赛41E(球的体积并)
球冠公式是\(\frac{\pi h^2(3R-h)}{3}\),这样再余弦公式用\(R_a\)和\(R_b\)导一导两个球冠的\(h\)就做完了.算是补了个camp时没做出来的小坑了. #inclu ...
- 引擎基本服务接口API介绍
Slickflow.NET 开源工作流引擎基础介绍(一) -- 引擎基本服务接口API介绍 https://www.cnblogs.com/slickflow/p/4807227.html 工作流术语 ...
- Net Core IIS Express In
IIS Express In Asp.Net Core IIS Express是一个Mini版的IIS,能够支持所有的Web开发任务,但是这种设计有一些缺陷,例如只能通过localhost:< ...
- aix OPATH ISSUE
issue 1: OPatch cannot find a valid oraInst.loc file to locate Central Inventory (OPatch failed with ...
- Zeppelin的入门使用系列之使用Zeppelin运行shell命令(二)
不多说,直接上干货! 前期博客 Zeppelin的入门使用系列之创建新的Notebook(一) 接下来,我将以ml-100k数据集,示范如何使用Spark SQL进行数据分析与数据可视化 因为 [ha ...
- Java选择排序算法
package com.jckb; /**选择排序 * * @author gx *算法原理: *第一个数和后面每个数进行比较,如果大于后面的数就进行位置交换, *第一次比较结束后得到了最小值 */ ...