Bloxorz很有意思的一个游戏(POJ3322)

POJ3322:Bloxorz游戏路径规划问题算法实战 本题本质是在三维状态空间$(x, y, \text{orientation})$ 上进行最短路径搜索,其中 orientation 编码为 0(直立)、1(横卧)、2(竖直)。由于每一步代价为1,适合采用BFS搜索。后续章节将围绕状态建模、BFS实现与碰撞检测展开系统性构建。当结构体含有指针或动态资源时,需确保深拷贝正确。但对于POJ3322这类纯值类型结构,无需额外干预。建议使用聚合初始化或构造函数明确赋值,避免未定义行为。 阅读详情

Description

Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which makes him excited. It's a game about rolling a box to a specific position on a special plane. Precisely, the plane, which is composed of several unit cells, is a rectangle shaped area. And the box, consisting of two perfectly aligned unit cube, may either lies down and occupies two neighbouring cells or stands up and occupies one single cell. One may move the box by picking one of the four edges of the box on the ground and rolling the box 90 degrees around that edge, which is counted as one move. There are three kinds of cells, rigid cells, easily broken cells and empty cells. A rigid cell can support full weight of the box, so it can be either one of the two cells that the box lies on or the cell that the box fully stands on. A easily broken cells can only support half the weight of the box, so it cannot be the only cell that the box stands on. An empty cell cannot support anything, so there cannot be any part of the box on that cell. The target of the game is to roll the box standing onto the only target cell on the plane with minimum moves.


The box stands on a single cell

The box lies on two neighbouring cells, horizontally

The box lies on two neighbouring cells, vertically

After Little Tom passes several stages of the game, he finds it much harder than he expected. So he turns to your help.

Input

Input contains multiple test cases. Each test case is one single stage of the game. It starts with two integers R and C(3 ≤ R, C ≤ 500) which stands for number of rows and columns of the plane. That follows the plane, which contains R lines and C characters for each line, with 'O' (Oh) for target cell, 'X' for initial position of the box, '.' for a rigid cell, '#' for a empty cell and 'E' for a easily broken cell. A test cases starts with two zeros ends the input.

It guarantees that

  • There's only one 'O' in a plane.
  • There's either one 'X' or neighbouring two 'X's in a plane.
  • The first(and last) row(and column) must be '#'(empty cell).
  • Cells covered by 'O' and 'X' are all rigid cells.

Output

For each test cases output one line with the minimum number of moves or "Impossible" (without quote) when there's no way to achieve the target cell.  

Sample Input

7 7
#######
#..X###
#..##O#
#....E#
#....E#
#.....#
#######
0 0

Sample Output

10

--------------------------------------------------------------------------------------------------------------
游戏很有意思,很智力~有兴趣可以到这个地方去玩玩~
关于这题,没有游戏中那种可以搭桥的情况~也就是说整个maze不会变,那总共就有500*500*5种状态了。
典型的BFS,可以记录其中某个格子的坐标,然后再用一个int变量来记录这个格子和另一个格子的相对位置。
0:上
1:右
2:下
3:左
以上是2个格子没有重叠的情况,假如重叠,那就把状态设为4。
当且仅当格子状态为4,并且位于终点时,才算成功。
4k的代码,写的我手有点麻~
-------------------------------------code----------------------------------------------------------------------
  1. #include<iostream>
  2. #include<queue>
  3. using namespace std;
  4. bool vis[500][500][5];
  5. struct NODE
  6. {
  7.     int i,j,floor,state; 
  8. };
  9. int mv[4][2]={-1,0,0,1,1,0,0,-1},r,c,si[2],sj[2],k;
  10. char maze[501][501];
  11. void init ( )
  12. {
  13.     int i, j;
  14.     k=0;
  15.     memset(vis,0,sizeof(vis));
  16.     for ( i=0 ; i<r ; i++ )
  17.     {
  18.         scanf("%s",maze[i]);
  19.         for ( j=0 ; j<c ; j++ )
  20.             if ( maze[i][j]=='X' )
  21.                 si[k]=i,sj[k++]=j;
  22.     }
  23. }
  24. // 返回两个点的相对位置的状态
  25. int mark ( int p1, int q1 , int p2 , int q2 )
  26. {
  27.     if ( p2-p1==-1 && q2-q1==0 )
  28.         return 0;
  29.     if ( p2-p1==0 && q2-q1==1 )
  30.         return 1;
  31.     if ( p2-p1==1 && q2-q1==0 )
  32.         return 2;
  33.     if ( p2-p1==0 && q2-q1==-1 )
  34.         return 3;
  35. }
  36. void bfs ( )
  37. {
  38.     NODE temp,head;
  39.     queue<NODE> que;
  40.     int i,tm1,tn1,tm2,tn2;
  41.     if ( k==1 )
  42.     {
  43.         head.i=si[0],head.j=sj[0];
  44.         head.floor=0;
  45.         head.state=4;
  46.         que.push(head);
  47.         vis[head.i][head.j][4]=vis[head.i][head.j][5]=true;
  48.     }
  49.     else
  50.     {
  51.         head.i=si[0],head.j=sj[0];
  52.         head.floor=0;
  53.         head.state=mark(si[0],sj[0],si[1],sj[1]);
  54.         que.push(head);
  55.         vis[si[0]][sj[0]][mark(si[0],sj[0],si[1],sj[1])]=vis[si[1]][sj[1]][mark(si[1],sj[1],si[0],sj[0])]=true;
  56.     }
  57.     while ( !que.empty() )
  58.     {
  59.         head=que.front();
  60. //      cout<<"*******************************"<<endl;
  61.         //if ( head.state>3 )
  62.         //  cout<<head.i<<" "<<head.j<<" "<<head.floor<<" out"<<endl;
  63.         //else
  64.         //  cout<<head.i<<" "<<head.j<<" "<<head.i+mv[head.state][0]<<" "<<head.j+mv[head.state][1]<<" "<<head.floor<<" out"<<endl;
  65.         que.pop() ;
  66. // 先考虑2个格子重叠的状态
  67.         if ( head.state>3 )
  68.             for ( i=0 ; i<4 ; i++ )
  69.             {
  70.                 tm1=head.i+mv[i][0],tn1=head.j+mv[i][1];
  71.                 tm2=tm1+mv[i][0],tn2=tn1+mv[i][1];
  72.                 if ( tm2>=0 && tm2<r && tn2>=0 && tn2<c && maze[tm1][tn1]!='#' && maze[tm2][tn2]!='#' 
  73.                     && !vis[tm1][tn1][mark(tm1,tn1,tm2,tn2)] && !vis[tm2][tn2][mark(tm2,tn2,tm1,tn1)] )
  74.                 {
  75.                     vis[tm1][tn1][mark(tm1,tn1,tm2,tn2)]=vis[tm2][tn2][mark(tm2,tn2,tm1,tn1)]=true;
  76.                     temp.i=tm1,temp.j=tn1,temp.floor=head.floor+1,temp.state=mark(tm1,tn1,tm2,tn2);
  77.                     que.push(temp);
  78.                     //if ( temp.state>3 )
  79.                     //  cout<<temp.i<<" "<<temp.j<<" "<<temp.floor<<" in"<<endl;
  80.                     //else
  81.                     //  cout<<temp.i<<" "<<temp.j<<" "<<temp.i+mv[temp.state][0]<<" "<<temp.j+mv[temp.state][1]<<" "<<temp.floor<<" in"<<endl;
  82.                 }
  83.             }
  84.         else
  85.         {
  86.             for ( i=0 ; i<4 ; i++ )
  87.             {
  88.                 if ( i==head.state || i==(head.state+2)%4 )
  89.                     continue;
  90.                 tm1=head.i+mv[i][0],tn1=head.j+mv[i][1];
  91.                 tm2=tm1+mv[head.state][0],tn2=tn1+mv[head.state][1];
  92.                 if ( tm1>=0 && tm1<r && tn1>=0 && tn1<c  && tm2>=0 && tm2<r && tn2>=0 && tn2<c && maze[tm1][tn1]!='#' && maze[tm2][tn2]!='#' 
  93.                     && !vis[tm1][tn1][head.state] && !vis[tm2][tn2][(head.state+2)%4] )
  94.                 {
  95.                     vis[tm1][tn1][head.state]=vis[tm2][tn2][(head.state+2)%4]=true;
  96.                     temp.i=tm1,temp.j=tn1,temp.floor=head.floor+1,temp.state=head.state;
  97.                     que.push(temp);
  98.                     //if ( temp.state>3 )
  99.                     //  cout<<temp.i<<" "<<temp.j<<" "<<temp.floor<<" in"<<endl;
  100.                     //else
  101.                     //  cout<<temp.i<<" "<<temp.j<<" "<<temp.i+mv[temp.state][0]<<" "<<temp.j+mv[temp.state][1]<<" "<<temp.floor<<" in"<<endl;
  102.                 }
  103.             }
  104.             tm1=head.i+mv[(head.state+2)%4][0],tn1=head.j+mv[(head.state+2)%4][1];
  105.             if ( tm1>=0 && tm1<r && tn1>=0 && tn1<c && maze[tm1][tn1]!='#' && maze[tm1][tn1]!='E' 
  106.                 && !vis[tm1][tn1][4] )
  107.             {
  108.                 if (maze[tm1][tn1]=='O')
  109.                 {
  110.                     printf("%d/n",head.floor+1);
  111.                     return ;
  112.                 }
  113.                 vis[tm1][tn1][4]=true;
  114.                 temp.i=tm1,temp.j=tn1,temp.floor=head.floor+1,temp.state=4;
  115.                 que.push(temp);
  116.                 //if ( temp.state>3 )
  117.                 //      cout<<temp.i<<" "<<temp.j<<" "<<temp.floor<<" in"<<endl;
  118.                 //  else
  119.                 //      cout<<temp.i<<" "<<temp.j<<" "<<temp.i+mv[temp.state][0]<<" "<<temp.j+mv[temp.state][1]<<" "<<temp.floor<<" in"<<endl;
  120.             }
  121.             tm1+=3*mv[head.state][0],tn1+=3*mv[head.state][1];
  122.             if ( tm1>=0 && tm1<r && tn1>=0 && tn1<c && maze[tm1][tn1]!='#' && maze[tm1][tn1]!='E' 
  123.                 && !vis[tm1][tn1][4] )
  124.             {
  125.                 if ( maze[tm1][tn1]=='O' )
  126.                 {
  127.                     printf("%d/n",head.floor+1);
  128.                     return ;
  129.                 }
  130.                 vis[tm1][tn1][4]=true;
  131.                 temp.i=tm1,temp.j=tn1,temp.floor=head.floor+1,temp.state=4;
  132.                 que.push(temp);
  133.                 /*if ( temp.state>3 )
  134.                         cout<<temp.i<<" "<<temp.j<<" "<<temp.floor<<" in"<<endl;
  135.                     else
  136.                         cout<<temp.i<<" "<<temp.j<<" "<<temp.i+mv[temp.state][0]<<" "<<temp.j+mv[temp.state][1]<<" "<<temp.floor<<" in"<<endl;*/
  137.             }
  138.         }
  139.     }
  140.     printf("Impossible/n");
  141. }
  142. int main ( )
  143. {
  144.     //freopen("ans.txt","w",stdout);
  145.     while ( scanf("%d%d",&r,&c) && r && c )
  146.     {
  147.         init();
  148.         bfs();
  149.     }
  150. }

Bloxorz-开源 Bloxorz是一款益智游戏。 该游戏的目的是在每个阶段结束时使方块落入方Kong中。 立即下载

相关推荐

bloxorz 益智游戏

这是一款非常好玩的益智游戏,据说通关的人很少

POJ - 3322 Bloxorz I(BFS)

POJ - 3322 Bloxorz I #include<cstdio> #include<cstring> #include<queue> using namespace std; struct State { int x,y,lie; }; const int N = 510; int n,m; char g[N][N]; int dist[N][N][3]; bool check(int x,int y) { if(x<0||x>=

00后的博客 220

bloxorz中文版

很有意思的打法时间的游戏,有点类似于推箱子,但是比推箱子好玩。这个是中文版,比英文版看的舒服多了。 内附每关通关保存密码。

POJ 3322 Bloxorz I BFS

一道有趣的搜索题,用广搜比较好。注意记录状态即可, 然后更新好标记数组。每次是根据方块左上角的坐标来进行操作的。 判断能不能走的时候一定要注意占两个格的情况,到达终点时一定是竖起来才行,薄弱地带一定不能竖起来。 队列可以用STL 也可以用数组,不过用数组的话,交到G++上,可以优化到700ms或者更少 /* ID: sdj22251 PROG: subset LANG: C++ */ #in...

coolsooner 192

组态王7.5和SQLsever数据库交互

摘要:本文详细介绍了组态王7.5与SQL Server 2016数据库交互的实现流程,包括建立连接、数据存储与查询操作。主要内容涵盖ODBC数据源配置、数据库表格创建、数据插入及查询功能实现(含日期控件查询)

gsjkwg的博客 1580

从安装到跑通第一个例程:Halcon 20.11深度学习版环境搭建全记录

本文详细记录了Halcon 20.11深度学习版环境搭建的全过程,从安装配置到运行第一个例程,特别针对CUDA版本冲突、算子验证和样本数据预处理等常见问题提供解决方案。通过实战案例展示PCB缺陷分类流程,帮助工程师快速掌握工业级图像处理技术,提升深度学习模型在工业质检中的应用效率。

weixin_28739079的博客 221

poj3322 Bloxorz I(滚箱子游戏) 状压BFS

题目链接: POJ3322 游戏链接: http://www.4399.com/flash/6860_3.htm 题意: 有一个长方体,给出它的起始位置(可能竖着,可能躺着) 问它通过滚动最少多少步能到达终点 解题思路: BFS   由于每一步可能有竖着和横着两种情况,如果是躺着,不可能记录两个坐标, 我们只需要记录靠左上的节点即可,

旧时光 1529

【Isaac Sim】无头服务器远程桌面连接实战:Turbovnc配置与常见问题解决

本文详细介绍了在无头GPU服务器上通过Turbovnc远程桌面连接并运行NVIDIA Isaac Sim的实战教程。针对无图形界面服务器运行仿真软件的核心痛点,文章提供了从Turbovnc安装配置、SSH隧道建立,到以普通用户身份启动服务、解决GLXBadFBConfig等常见图形错误的完整方案,帮助开发者在云端高效部署机器人仿真环境。

weixin_29254673的博客 773

POJ 3322 Bloxorz I(BFS:求迷宫最短路径)

POJ 3322 Bloxorz I(BFS:求迷宫最短路径) http://poj.org/problem?id=3322 题意:有一个R*C的网格,网格中有3种格子:正常格子,脆弱格子以及空格子.现在给你一个1*2立方体的初始位置,要你求出将该立方体移动到终点所需要的最小步数. 分析:其实和一般的BFS求最短路径没本质区别,就是状态设计和移动可能复杂点.        我们令1

code 2192

【Agent】多智能体框架MetaGPT入门教程

创建一个 Action 类的子类 SimpleWriteCode,子类中定义好 prompt,并解析返回结果。在 MetaGPT 中,

酒酿小圆子呀~ 3137

DEM高程数据的获取、合并与坐标转换

DEM高程数据的获取、合并与坐标转换一、DEM数据的获取二、数据合并三、投影转换方法一四、投影转换方法二 今天用DEM数据做了一个坡度分析,数据使用过程中涉及到投影坐标转换,由于不是很熟悉所以费了一番功夫。经过一番折腾总结出两个方法,方法一自认为比较便捷的方法,即通过BIGMAP软件中工具列表中的投影转换功能进行。方法二为传统方法,即在Arcgis中用投影栅格工具进行转换。 一、DEM数据的获取 在地理空间数据云网站下载DEM数据(精度包括30米和90米),数据格式为tif格式或img格式,坐标为WGS_1

weixin_48625651的博客 1万+

POJ 3322 Bloxorz(算竞进阶习题)

bfs 标准广搜题,主要是把每一步可能的坐标都先预处理出来,会好写很多 每个状态对应三个限制条件,x坐标、y坐标、lie=0表示直立在(x,y),lie=1表示横着躺,左半边在(x,y),lie=2表示竖着躺,上半边在(x,y) #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace std; typedef lo...

weixin_33937499的博客 171

【C++】【STL算法】数据窄化及代码安全性

本文系统探讨了C++工程中数据窄化(narrowing conversion)的隐患与解决方案。数据窄化指将高精度/大范围类型转换为低精度/小范围类型,虽语法合法但会导致静默精度损失。其危险性体现在:错误隐蔽、STL会放大问题、数值错误具有传播性。现代C++要求窄化必须显式声明,文中提出四种工程解决方案:显式转换、边界统一转换、范围检查转换和使用GSL工具。建议在系统边界集中处理窄化,保持计算链路类型一致性,并通过分层策略(建模用double,控制用float)确保数值稳定性。核心思想是让窄化成为清晰可控的

Double Galaxy 80

POJ3322bloxorz

这道题目很适合学习广度优先搜搜的小盆友: Bloxorz是一个风靡世界的小游戏。Bloxorz的地图是一个N行M列的矩阵,每个位置可能是硬地(用.表示)、易碎地面(用E表示)、禁地(用#表示)、起点(用X表示)或终点(用O表示)。你的任务是操作一个1*1*2的长方体。这个长方体在地面上有两种放置形式,“立”在地面上(1*1的面接触地面)或者“躺”在地面上(1*2的面接触地面)。在每一步操作中,可以按上下左右四个键之一。按下之后,长方体向对应的方向沿着棱滚动90度。任意时刻,长方体不能有任何部位接触禁.

zhagoodwell查的博客 1244

SpringBoot整合JWT实战:从零构建无状态认证系统,详解Token生成、验证与安全最佳实践

JWT在SpringBoot中的实现与应用 摘要:本文介绍了JWT(JSON Web Token)的基本概念、与Session机制的对比,以及SpringBoot项目中JWT的整合实现。JWT由Header、Payload和Signature三部分组成,具有无状态、跨域支持等优势。文章详细展示了如何在SpringBoot项目中配置JWT环境,封装JWT工具类来实现Token的生成、解析和验证功能,包括密钥管理、自定义声明、签名验证等核心操作。通过对比表格和生活化比喻,帮助读者理解JWT与传统Session的

本博客聚焦 YOLOv11 全流程落地,涵盖架构优化、数据集处理、训练技巧与多场景部署,兼及国产数据库、Java 开发与 AI 模型应用,内容兼顾理论与工程实践,为开发者提供系统干货,助力高效提升技术能力。 1775

外骨骼机器人(二):自适应振荡器

振荡器是一种数学工具,可以用于实时跟踪、预测类周期信号的频率、相位、幅值等,而助行外骨骼机器人需要自动适应人体的行走频率、幅度,两者相结合,就能使助行外骨骼机器人拥有更舒适、更自然的行走步态。 ......

行者无疆的博客 4264

POJ 3322 Bloxorz I

题目链接:http://poj.org/problem?id=3322 源自Bloxorz游戏:点此试玩 挺有意思的一题,搜索本身不难,主要在表示状态上想了很长时间。 木块的状态可以压缩为三种:直立,横放,竖放。每种状态记录最上边或者最右边的坐标即可。 初始状态不一定是竖直放的,我玩了几关游戏,初始状态都是竖直放的,我就默认为初始状态竖直了于是WA了几次…… 也可能有这种情况:...

aegt43853的博客 104

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Bloxorz I POJ - 3322

Bloxorz I POJ - 3322

weixin_29216119的博客 1178

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Bloxorz POJ3322

Bloxorz POJ3322 思路 题干在这:POJ3322 学习广搜,抄的算法竞赛进阶指南的事例代码 ac代码 #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<queue> using namespace std; str...

没有自旋的π介子 229

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

poj3322 Bloxorz I

bfs暴搜

YHaX的博客 551

POJ3322 Bloxorz I 题解

20min内单独现写AC此题,DFS、BFS基本过关了。

weixin_42178241的博客 274

【POJ 3322】 Bloxorz I

【题目链接】 http://poj.org/problem?id=3322 【算法】 广度优先搜索 【代码】 #include <algorithm> #include <bitset> #include <cctype> #include <ce...

123

POJ 3322 BFS

题意 传送门 POJ 3322 Bloxorz I 题解 长方体当前的状态为其横、纵坐标与摆放状态组成的三元组,为了方便表示,只取长方体左上方的位置作为横、纵坐标状态,BFSBFSBFS 求解即可。 #include <algorithm> #include <cstdio> #include <cstring> #include <queue> using namespace std; #define maxn 505 struct node { i

neweryyy的博客 194

POJ - 3322 Bloxorz I(bfs+状态设计)

题目链接:点击查看 题目大意:模拟Bloxorz小游戏找出最优解,简单说一下规则,给出一个n*m的矩阵,其中,"#"代表墙,"X"代表起点,"O"代表终点,"E"代表脆弱道路,即承受不住立着的方块,"."代表普通道路 题目分析:因为方块总共有三种状态:立着(占1格)、竖着(占2格)、横着(占2格),我们可以将占两个的两个状态压缩到一格中,竖着的(上下分布)我们规定有效方格在上面,横着的(左右分...

Falcon的博客 688
上一篇: 利用stl的map判重poj3087
下一篇: pku上的数据结构题
chinaeli
博客等级 码龄18年 13粉丝 21原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值