【题目描述】

	 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验证码程序

    1.设计思想利用random的随机生成数字,利用for循环控制随机数字的个数来控制验证码的输出.利用JFrame实现布局的管理,对登录框内容的位置进行管理. 2.流程图 3.源代码 denglu类 i ...

  2. NOIP2016 D1T1 玩具谜题

    洛谷P1563 看完了noip2017觉得noip2016是真的简单……2017第一题就卡住2016第一题10分钟AC 思路: m<=100000很明显暴力模拟就可以 唯一有一点点难度的地方就是 ...

  3. 完美解决linux不能编辑sshd_cofig和实现xshell远程连接的问题

    第一步:我们使用命令行vim /etc/ssh/sshd_config   执行修改,强制保持  :wq!  系统不让我们修改这个文件 "/etc/ssh/sshd_config" ...

  4. 配置 app.js 文件

    pp.js 中存放全局的 JavaScript 逻辑. 示例: App({ onLaunch: function () { console.log('SWAN launch'); }, onShow: ...

  5. 约数定理(two)

    筛约数个数和 理论基础: 1.对n质因数分解,n=p1^k1 * p2^k2 * p3^k3 …… 则n的约数个数为(k1+1)*(k2+1)*(k3+1)…… 2.线性筛素数时,用i和素数pj来筛掉 ...

  6. apache Internal Server Error 解决方法

    https://blog.csdn.net/qq_33684377/article/details/78536548 https://blog.csdn.net/LJFPHP/article/deta ...

  7. android 任务栈及启动模式

    1.一个应用程序一般都是由多个activity组成的.2.任务栈(task stack)(别名back stack后退栈) 记录存放用户开启的activity的.3.一个应用程序一被开启系统就给他分配 ...

  8. A - Biorhythms (第三周)

    A - Biorhythms 链接:https://vjudge.net/contest/154063#problem Description 人生来就有三个生理周期,分别为体力.感情和智力周期,它们 ...

  9. #20175201张驰 实验三 敏捷开发与XP实践

    实验步骤 (一)敏捷开发与XP 一.敏捷开发与XP实践-1 ①实验要求: 敏捷开发与XP实践 http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse ...

  10. foreach(增强for循环)和for的区别

    https://www.cnblogs.com/XiaojianGo/p/7471860.html 首先说一下foreach有的也叫增强for循环,foreach其实是for循环的一个特殊简化版. 再 ...