【题目描述】

	 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.

【算法】

	貌似没啥算法,就是BFS,但是写起来很烦,%lyd,大佬的代码为什么就这么清晰明了。。。。

【题目链接】

Bloxorz I

【代码】

#include <stdio.h>
#include <queue>
using namespace std;
struct rec{ int x,y,state; }st,ed;
char s[510][510];
int m,n,d[510][510][3];
queue<rec> q;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
bool valid(int x,int y) {
return x>=1&&x<=m&&y>=1&&y<=n;
}
void parse_st_ed() {
for(int i=1;i<=m;i++) {
for(int j=1;j<=n;j++) {
if(s[i][j]=='O') {
ed.x=i,ed.y=j,s[i][j]='.';
}else if(s[i][j]=='X') {
for(int k=0;k<4;k++) {
int x=i+dx[k],y=j+dy[k];
if(valid(x,y)&&s[x][y]=='X') {
st.x=min(x,i),st.y=min(y,j);
st.state=x==i?1:2;
s[i][j]=s[x][y]='.';
break;
}
}
if(s[i][j]=='X') st.x=i,st.y=j,st.state=0;
}
}
}
}
const int next_x[3][4]={ {0,0,-2,1},{0,0,-1,1},{0,0,-1,2} };
const int next_y[3][4]={ {-2,1,0,0},{-1,2,0,0},{-1,1,0,0} };
const int next_state[3][4]={ {1,1,2,2},{0,0,1,1},{2,2,0,0} };
bool valid(rec k) {
if(!valid(k.x,k.y)) return 0;
if(s[k.x][k.y]=='#') return 0;
if(k.state==0&&s[k.x][k.y]=='E') return 0;
if(k.state==1&&s[k.x][k.y+1]=='#') return 0;
if(k.state==2&&s[k.x+1][k.y]=='#') return 0;
return 1;
}
int bfs() {
while(q.size()) q.pop();
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
d[i][j][0]=d[i][j][1]=d[i][j][2]=-1;
d[st.x][st.y][st.state]=0;
q.push(st);
while(q.size()) {
rec now=q.front(); q.pop();
for(int i=0;i<4;i++) {
rec next;
next.x=now.x+next_x[now.state][i];
next.y=now.y+next_y[now.state][i];
next.state=next_state[now.state][i];
if(!valid(next)) continue;
if(d[next.x][next.y][next.state]==-1) {
d[next.x][next.y][next.state]
=d[now.x][now.y][now.state]+1;
if(next.x==ed.x&&next.y==ed.y&&!next.state) return d[next.x][next.y][0];
q.push(next);
}
}
}
return -1;
}
int main() {
while(~scanf("%d%d",&m,&n)&&m) {
for(int i=1;i<=m;i++) scanf("%s",s[i]+1);
parse_st_ed();
int ans=bfs();
if(ans==-1) puts("Impossible");
else printf("%d\n",ans);
}
return 0;
}

Bloxorz I (poj3322) (BFS)的更多相关文章

  1. Bloxorz I POJ - 3322 (bfs)

    Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which m ...

  2. poj3322 Bloxorz I

    Home Problems       Logout -11:24:01     Overview Problem Status Rank A B C D E F G H I J K L M N O ...

  3. Bloxorz I (poj 3322 水bfs)

    Language: Default Bloxorz I Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5443   Acce ...

  4. POJ3322 Bloxorz I 无脑广搜(我死了。。。)

    多测不清空,爆零两行泪....我死了QWQ 每个节点3个状态:横坐标,纵坐标,和方向 说一下方向:0:立着,1:竖着躺着,上半部分在(x,y),2:横着躺着,左半部分在(x,y) 然后就有了常量数组: ...

  5. 寒假训练——搜索 E - Bloxorz I

    Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which m ...

  6. POJ 3322 Bloxorz I

    首先呢 这个题目的名字好啊 ORZ啊 如果看不懂题意的话 请戳这里 玩儿几盘就懂了[微笑] http://www.albinoblacksheep.com/games/bloxorz 就是这个神奇的木 ...

  7. 图的遍历(搜索)算法(深度优先算法DFS和广度优先算法BFS)

    图的遍历的定义: 从图的某个顶点出发访问遍图中所有顶点,且每个顶点仅被访问一次.(连通图与非连通图) 深度优先遍历(DFS): 1.访问指定的起始顶点: 2.若当前访问的顶点的邻接顶点有未被访问的,则 ...

  8. 【BZOJ-1656】The Grove 树木 BFS + 射线法

    1656: [Usaco2006 Jan] The Grove 树木 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 186  Solved: 118[Su ...

  9. POJ 3278 Catch That Cow(bfs)

    传送门 Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 80273   Accepted: 25 ...

随机推荐

  1. java:序列化Serializable 接口

    java:序列化Serializable 接口 public class SerializePerson implements Serializable { private String name; ...

  2. os模块、sys模块、json模块、pickle模块、logging模块

    目录 os模块 sys模块 json模块 pickle模块 logging模块 os模块 功能:与操作系统交互,可以操作文件 一.对文件操作 判断是否为文件 os.path.isfile(r'路径') ...

  3. 2019年开发App记录

    Pod 制作私有库参考 https://www.jianshu.com/p/f903ecf8e882 Pod私有库的升级 改代码部分,到Example文件夹执行pod install ,修改XXX.s ...

  4. linux文件系统的类型

    文件系统的类型 兄弟连介绍-Linux有四种基本文件系统类型:普通文件.目录文件.连接文件和特殊文件,可用file命令来识别. 普通文件:如文本文件.C语言元代码.SHELL脚本.二进制的可执行文件等 ...

  5. Oracle-存储过程实现更改用户密码

    --调用存储过程实现更改DB用户密码 CREATE OR REPLACE PROCEDURE MODUSERPW(USER_NAME VARCHAR2,USER_PW VARCHAR2)ISSQLTX ...

  6. [CSP-S模拟测试]:简单的操作(二分图+图的直径)

    题目描述 从前有个包含$n$个点,$m$条边,无自环和重边的无向图. 对于两个没有直接连边的点$u,v$,你可以将它们合并.具体来说,你可以删除$u,v$及所有以它们作为端点的边,然后加入一个新点$x ...

  7. 插头DP讲解+[BZOJ1814]:Ural 1519 Formula 1(插头DP)

    1.什么是插头$DP$? 插头$DP$是$CDQ$大佬在$2008$年的论文中提出的,是基于状压$D$P的一种更高级的$DP$多用于处理联通问题(路径问题,简单回路问题,多回路问题,广义回路问题,生成 ...

  8. 大数据笔记(六)——HDFS的底层原理:JAVA动态代理和RPC

    一.Java的动态代理对象 实现代码如下: 1.接口类MyService package hdfs.proxy; public interface MyService { public void me ...

  9. Xcode工程文件pbxproj

    Xcode工程文件pbxproj Xcode会去读Project.pbxproj文件,把pbxproj转成plist文件,看起根目录结构 rootObject:指向的是我们的工程对象.(对应一个24个 ...

  10. benchmarks

    系统性能测试 stream SPARK 测试 streaming benchmark https://github.com/yahoo/streaming-benchmarks