#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. 【Activiti学习之三】Activiti API(二)

    环境 JDK 1.8 MySQL 5.6 Tomcat 7 Eclipse-Luna activiti 6.0 一.流程定义1.中止与激活流程定义 package com.wjy.pd; import ...

  2. github打开慢,甚至打不开,怎么办,解决方案方法

    有人使用github后,在某些网络下发现打开慢,甚至打不开,这都是因为他是国外站:目前互联网的连接机制导致超过一定的路由节点的连接就会出现这个问题,解决办法就是直接告诉本机ip.不要先层层询问域名转i ...

  3. ASP.NET Core WebApi构建API接口服务实战演练

    一.ASP.NET Core WebApi课程介绍 人生苦短,我用.NET Core!提到Api接口,一般会想到以前用到的WebService和WCF服务,这三个技术都是用来创建服务接口,只不过Web ...

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

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

  5. c++篇 vc++2010设置和c#一样的代码段,vs2010 两下tab设置

    设置vs2010 tab敲两下出 for 片段,因为vs2010的代码片段是在番茄助手里设置的...代码片段管理器中不能设置c++ 所以我只能安装一个番茄助手了... 然后就是修改番茄助手内的[提示] ...

  6. centos8 安装 docker

    centos 安装docker  官方参考地址:https://docs.docker.com/install/linux/docker-ce/centos/ 里面包含包下载地址: https://d ...

  7. Tp中使用Xunsearch

    可以将安装目录下的核心代码拷贝到Vendor中. 命名为xunsearch. 然后引入使用. vendor('xunsearch.lib.XS'); $xs = new \XS('demo'); // ...

  8. 【C学习笔记】一

    一.运算符优先级 逻辑非>算术运算符>关系运算符>逻辑运算符>赋值运算符>逗号运算符 逻辑运算符>条件运算符>赋值运算符 对于if的执行语句,如果是一条语句那 ...

  9. VS2019 Nuget找不到包的问题处理

    VS不记得改了什么设置之后,发现找不到EF 解决办法 1.点击右侧的设置按钮 2.弹出窗中左侧树形结构选择“程序包源”,再点击右上方的添加按钮 输入一下信息:https://www.nuget.org ...

  10. Mysql中的排序查询

    进阶3:排序查询 语法: select 查询列表 from 表 [where 筛选条件]order by 排序列表 [asc 升序 | desc降序] 例子 查询员工信息,要求工资从高到低 SELEC ...