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.

bfs暴搜。保存状态的时候,记录摆法(三种)和左上角方块的位置,用打表数组转移。

#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int map[510][510],m,n,kk[3][4]={{2,2,1,1},{1,1,0,0},{0,0,2,2}};
int xx[3][4]={{1,-2,0,0},{1,-1,0,0},{2,-1,0,0}};
int yy[3][4]={{0,0,-2,1},{0,0,-1,2},{0,0,-1,1}};
bool vis[510][510][3];
struct con
{int x,y,k,t;bool ok(){if (vis[x][y][k]) return 0;if (k==0)return x>=1&&x<=n&&y>=1&&y<=m&&(!map[x][y]);if (k==1)return x>=1&&x<=n&&y>=1&&y<m&&map[x][y]<2&&map[x][y+1]<2;return x>=1&&x<n&&y>=1&&y<=m&&map[x][y]<2&&map[x+1][y]<2;}bool meet(con ccc){return x==ccc.x&&y==ccc.y&&k==ccc.k;}
}c1,c2,tar;
queue<con> q;
char s[510];
int main()
{int i,j,k,p,x,y,z,w,cnt;bool flag;while (scanf("%d%d",&n,&m)&&n&&m){memset(vis,0,sizeof(vis));while (!q.empty()) q.pop();cnt=0;for (i=1;i<=n;i++){scanf("%s",s+1);for (j=1;j<=m;j++)if (s[j]=='#') map[i][j]=2;else{if (s[j]=='E') map[i][j]=1;else{map[i][j]=0;if (s[j]=='O') tar=(con){i,j,0,0};if (s[j]=='X'){cnt++;if (cnt==1) x=i,y=j;else z=i,w=j;}}}}if (cnt==1) q.push((con){x,y,0,0}),vis[x][y][0]=1;else{if (x==z) q.push((con){x,y,1,0}),vis[x][y][1]=1;else q.push((con){x,y,2,0}),vis[x][y][2]=1;}flag=0;while (!q.empty()){c1=q.front();q.pop();for (i=0;i<4;i++){c2=(con){c1.x+xx[c1.k][i],c1.y+yy[c1.k][i],kk[c1.k][i],c1.t+1};if (!c2.ok()) continue;if (c2.meet(tar)){flag=1;printf("%d\n",c2.t);break;}q.push(c2);vis[c2.x][c2.y][c2.k]=1;}if (flag) break;}if (!flag) printf("Impossible\n");}
}

poj3322 Bloxorz I相关推荐

  1. POJ-3322 Bloxorz I

    题目描述 Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' wh ...

  2. POJ3322 Bloxorz I BFS

    题目链接 http://poj.org/problem?id=3322 分析 每次操作,地图不会改变,变化的坐标及放置方式可以设为状态,进行BFS. 预处理出各种放置方式下,向各个方向移动后状态的变化 ...

  3. POJ3322 Bloxorz “迷宫”类经典例题

    题目大意 游戏地图是一个N行M列的矩阵,每个位置可能是硬地(用"."表示).易碎地面(用"E"表示).禁地(用"#"表示).起点(用&quo ...

  4. POJ3322 Bloxorz I(BFS)

    很有意思的一个益智小游戏.题目我就不描述了,玩过的人都知道规则. 题目传送门:http://poj.org/problem?id=3322 空格子不能走(可以看成墙),标号为E表示脆弱的格子,箱子在上 ...

  5. POJ3322Bloxorz I

    POJ3322 Bloxorz I 暴搜,next数组与处理一下(小技巧) 1 #include <cstdio> 2 #include <iostream> 3 #inclu ...

  6. 高级搜索题集(夏天的风分类)

    基础的搜索BFS和DFS,自己找题切吧... 高级搜索的题集就在下面,自己看着办吧... 努力爆搜,努力剪枝吧~~~ [Level 1] HDOJ-1429 胜利大逃亡(续)    迷宫问题,有钥匙和 ...

  7. Bloxorz POJ3322

    Bloxorz POJ3322 思路 题干在这:POJ3322 学习广搜,抄的算法竞赛进阶指南的示例代码 ac代码 #include<cstdio> #include<iostrea ...

  8. Bloxorz I (poj3322) (BFS)

    [题目描述] It's a game about rolling a box to a specific position on a special plane. Precisely, the pla ...

  9. Bloxorz I [POJ3322]

    题面描述 一个游戏,为一个NNN行MMM列第二矩阵,位置可能是硬地("...").易碎地面("EEE").禁地("#").起点(" ...

最新文章

  1. chrome弱网_请你进行一下弱网模拟
  2. 现在,Serverless 真的已经成熟了吗?
  3. mysql中count的用法
  4. 宏BOOST_TEST_REF的用法程序
  5. CDH集群安装配置(四)- mysql 的安装
  6. 【Http】一文备忘Http状态码(406,415,422)
  7. P1447-[NOI2010]能量采集【GCD,数论,容斥】
  8. linux中标准I/O 文件I/O 及库
  9. Nginx的应用之动静分离
  10. java null指针_注意:java 这些地方经常发生 NullPointerException(空指针)异常
  11. [视频教程]用Unity3d开发跳一跳小游戏
  12. IE8浏览器跨域接口访问异常的解决办法
  13. 使用Pack200压缩你的代码
  14. 纯新手DSP编程--5.31--DSP/BIOS中的数据交换
  15. 拓端tecdat|R语言使用HAR-RV预测实际波动率Realized Volatility案例
  16. model.train() model.eval()
  17. Node.js .sh scripts Manager
  18. 泰坦尼克号python数据分析统计服_Python数据分析及可视化实例之泰坦尼克号存活预测(23)...
  19. 信雅达银行外包怎么样_光大银行信用卡逾期2年3万会坐牢吗?信用卡逾期半年要起诉...
  20. 【Magick++】配置开发环境

热门文章

  1. linux-ubuntu Got permission denied while trying to connect to the Docker daemon socket at
  2. adaptec raid linux,adaptec raid 卡管理软件在windows和linux下的安装使用介绍.doc
  3. 将python项目文件加密
  4. STM32状态机编程实例——全自动洗衣机(上)
  5. python更新版本
  6. 如何将iPhone投屏到Mac电脑上?iphone投屏到mac方法
  7. 利用Nextcloud搭建个人私有网盘
  8. MMDetection专栏开篇
  9. Youtbe 4k 起播阶段时间花费分析
  10. 如何用pdfFactory Pro批改作业