#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<queue>
#define de system("pause");
using namespace std;
int r,c;
char s[][];
int aim[];
int ans=;
bool bz[][][];
bool check(int way,int x,int y)
{
if(x<||x>r||y<||y>c)return ;
if(way==)
{
if(s[x][y]=='#'||s[x][y+]=='#')return ;
if(bz[x][y][])return ;
}
if(way==)
{
if(s[x][y]=='#'||s[x+][y]=='#')return ;
if(bz[x][y][])return ;
}
if(way==)
{
if(s[x][y]=='#'||s[x][y]=='E')return ;
if(bz[x][y][])return ;
}
return ;
}
struct node
{
int way,x,y,step;
node(int wa,int xx,int yy,int ste)
{
way=wa;
x=xx;
y=yy;
step=ste;
}
};
queue<node> q;
void so(int x,int y,int way,int step)
{
bz[x][y][way]=;
q.push(node(way,x,y,step));
if(way==&&s[x][y]=='O')
{
// cout<<step<<endl;
ans=min(ans,step);
}
}
void bfs()
{
while(!q.empty())
{
node now=q.front();
int x=now.x,y=now.y,way=now.way,step=now.step;
q.pop();
// bz[x][y][way]=0;
if(way==)
{
if(check(,x-,y)) so(x-,y,,step+);
if(check(,x+,y)) so(x+,y,,step+);
if(check(,x,y-)) so(x,y-,,step+);
if(check(,x,y+)) so(x,y+,,step+);
}
if(way==)
{
if(check(,x-,y)) so(x-,y,,step+);
if(check(,x+,y)) so(x+,y,,step+);
if(check(,x,y-)) so(x,y-,,step+);
if(check(,x,y+)) so(x,y+,,step+);
}
if(way==)
{
if(check(,x-,y)) so(x-,y,,step+);
if(check(,x+,y)) so(x+,y,,step+);
if(check(,x,y-)) so(x,y-,,step+);
if(check(,x,y+)) so(x,y+,,step+);
} }
}
int main()
{
while()
{
while(q.size())q.pop();
memset(bz,,sizeof bz);
scanf("%d%d",&r,&c);
if(r==&&c==)break;
int a[][];
int cnt=;
ans=;
for(int i=;i<=r;++i)
{
scanf("%s",s[i]+);
for(int j=;j<=c;j++)
{
if(s[i][j]=='X')
{
++cnt;
a[cnt][]=i,a[cnt][]=j;
}
}
}
if(cnt==) q.push(node(,a[cnt][],a[cnt][],));
else
{
if(a[][]==a[][]) q.push(node(,a[][],a[][],));
else q.push(node(,a[][],a[][],));
}
bfs();
if(ans==)puts("Impossible");
else cout<<ans<<endl;
}
return ;
}

POJ 3322 Bloxorz的更多相关文章

  1. POJ 3322 Bloxorz I

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

  2. POJ 3322 Bloxorz(算竞进阶习题)

    bfs 标准广搜题,主要是把每一步可能的坐标都先预处理出来,会好写很多 每个状态对应三个限制条件,x坐标.y坐标.lie=0表示直立在(x,y),lie=1表示横着躺,左半边在(x,y),lie=2表 ...

  3. 【POJ 3322】 Bloxorz I

    [题目链接] http://poj.org/problem?id=3322 [算法] 广度优先搜索 [代码] #include <algorithm> #include <bitse ...

  4. Bloxorz I (poj 3322 水bfs)

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

  5. Bloxorz I POJ - 3322 (bfs)

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

  6. POJ 3322(广搜)

    ---恢复内容开始--- http://poj.org/problem?id=3322 题意:http://jandan.net/2008/01/24/bloxorz.html就是这个鬼游戏 我也是郁 ...

  7. poj很好很有层次感(转)

    OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...

  8. POJ题目分类推荐 (很好很有层次感)

    著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299 ...

  9. 【POJ】【2601】Simple calculations

    推公式/二分法 好题! 题解:http://blog.csdn.net/zck921031/article/details/7690288 这题明显是一个方程组……可以推公式推出来…… 然而这太繁琐了 ...

随机推荐

  1. [Gamma阶段]测试报告

    [Gamma阶段]测试报告 博客目录 测试方法及过程 在正式发布前,为检验后端各接口功能的正确性,后端服务器对压力的耐受程度,以及前端各页面.功能的运行情况,我们对我们的服务器及小程序进行了多种测试. ...

  2. log4j2使用RollingFile重启丢失日志问题

    <RollingFile name="cnkiLogRollingFileError" fileName="${logbigdata.dir}/Log8080/er ...

  3. gcc 在c代码中内嵌汇编调用c函数: 只是证明曾经我来过

    我怕我不写下来,将来我都不记得我还在 c 中嵌套过汇编语言,用汇编代码调用一个c函数的过程. 折腾了一下午,在网上查看相关的资料,然后照葫芦画瓢地在c代码中嵌套汇编,希望解决我所遇到的问题,可最后发现 ...

  4. 【数据结构与算法】k-d tree算法

    k-d tree算法 k-d树(k-dimensional树的简称),是一种分割k维数据空间的数据结构.主要应用于多维空间关键数据的搜索(如:范围搜索和最近邻搜索). 应用背景 SIFT算法中做特征点 ...

  5. 学习spring源码-可参考的资料

    剑指Spring源码(二) https://www.cnblogs.com/codebear/p/10374261.html 使用idea和gradle编译spring5源码https://blog. ...

  6. linux_utf

    LANG=en_US.utf8 export LC_ALL=en_US.utf8

  7. SpringApplication常见用法说明

    启动方式 方式1:在main方法中执行SpringApplication.run()这种方式来启动我们的工程 // 方式一 @SpringBootApplication public class Ap ...

  8. Effective.Java第56-66条(规范相关)

    56.  为所有已公开的API元素编写文档注释 要正确地记录API,必须在每个导出的类.接口.构造方法.方法和属性声明之前加上文档注释.如果一个类是可序列化的,还需要记录它的序列化形式. 文档注释在源 ...

  9. 避免maven package 打包时执行 mybatis-generator-maven-plugin 插件

    一.为什么打包时会执行该插件mybatis-generator-maven-plugin默认绑定了package的生命周期 二.如何解决如果在package和install 执行插件,修改pom中的配 ...

  10. tornado之websoket

    继承WebSoketHandler def open(self): # 当一个WebSoket连接建立之后被调用 def on_message(self, message): # 当客户端发送一个消息 ...