【题目描述】

	 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. ubuntu16.04 安装samba

    安装samba 1.更新当前软件 sudo apt-get upgrade sudo apt-get update sudo apt-get dist-upgrade 2.执行 sudo apt-ge ...

  2. zabbix监控A主机到B主机的网络质量

    采用zabbix自带的icmp ping即可进行监控: 1.安装fping 2.将fping安装后链接到/usr/sbin/fping下,设置组为zabbix; 3.增加监控项:icmpping[ip ...

  3. Excel: assign label to scatter chart using specific cell values

    ref: https://www.get-digital-help.com/custom-data-labels-in-x-y-scatter-chart/ Improve your X Y Scat ...

  4. 【微信小程序】使用vscode编写微信小程序项目

    1. 在微信开发者工具(以下简称:开发者)中新建一个模板微信小程序 2. 在开发者中将模拟器分隔开 3. 设置在保存时编译 4. 在vscode中打开项目目录 5. 下载代码提示插件 这样就可以在vs ...

  5. Linux root用户与普通用户时间不一致

    造成这种原因有多种,可能是安装软件时选的时区不是本国时间等等. 今天检查了root用户和oracle及grid用户的时间不一样,幸好数据库还没有正式应用,不然可能会造成时间差影响. 现在将同步的方法步 ...

  6. 通过Hadoop jmx收集Namenode,Jobtracker相关信息

    经常会有一些Hadoop监控的需求,例如datanode节点掉线,Tasktracker blacklist的数量,以及Namenode,Jobtracker的内存GC信息等. 之前采用Hadoop ...

  7. Day02 结构类型

    1.结构类型是值类型  (类是引用类型) 2.结构中也可以像类一样,定义 字段  属性  方法  但是不能给字段赋初始值 3.结构的构造方法中,必须为所有的字段赋值 4.不能为结构显示定义无参数的构造 ...

  8. vue2.0 之 douban (一)框架搭建 及 整体布局

    1.创建豆瓣项目 我们通过官方vue-cli初始化项目 vue init webpack douban 填写项目描述,作者,安装vue-router 初始化后,通过npm install安装依赖 cd ...

  9. el-date-picker用法

    需求:1.默认时间是当天开始到此刻的时间 2.快捷键为今天.昨天.最近一周.最近30天.最近90天 3.不可以清空,必选项

  10. 自定义控件 - 切换开关:SwitchView

    自定义控件一般的几个步骤:1.初始化相关背景图片,布局文件,自定义属性2.设置控件宽高OnMeasure()3.布局或者排版OnLayout()4.绘制控件OnDraw()5.处理触摸事件OnTouc ...