POJ 3322 Bloxorz
#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的更多相关文章
- POJ 3322 Bloxorz I
首先呢 这个题目的名字好啊 ORZ啊 如果看不懂题意的话 请戳这里 玩儿几盘就懂了[微笑] http://www.albinoblacksheep.com/games/bloxorz 就是这个神奇的木 ...
- POJ 3322 Bloxorz(算竞进阶习题)
bfs 标准广搜题,主要是把每一步可能的坐标都先预处理出来,会好写很多 每个状态对应三个限制条件,x坐标.y坐标.lie=0表示直立在(x,y),lie=1表示横着躺,左半边在(x,y),lie=2表 ...
- 【POJ 3322】 Bloxorz I
[题目链接] http://poj.org/problem?id=3322 [算法] 广度优先搜索 [代码] #include <algorithm> #include <bitse ...
- Bloxorz I (poj 3322 水bfs)
Language: Default Bloxorz I Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5443 Acce ...
- Bloxorz I POJ - 3322 (bfs)
Little Tom loves playing games. One day he downloads a little computer game called 'Bloxorz' which m ...
- POJ 3322(广搜)
---恢复内容开始--- http://poj.org/problem?id=3322 题意:http://jandan.net/2008/01/24/bloxorz.html就是这个鬼游戏 我也是郁 ...
- poj很好很有层次感(转)
OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...
- POJ题目分类推荐 (很好很有层次感)
著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299 ...
- 【POJ】【2601】Simple calculations
推公式/二分法 好题! 题解:http://blog.csdn.net/zck921031/article/details/7690288 这题明显是一个方程组……可以推公式推出来…… 然而这太繁琐了 ...
随机推荐
- jvm jdk jre 关系
JDK : Java Development ToolKit(Java开发工具包).JDK是整个JAVA的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工 ...
- Beta冲刺(3/7)——2019.5.25
作业描述 课程 软件工程1916|W(福州大学) 团队名称 修!咻咻! 作业要求 项目Beta冲刺(团队) 团队目标 切实可行的计算机协会维修预约平台 开发工具 Eclipse 团队信息 队员学号 队 ...
- SQL系列(十一)—— 函数(function)
SQL中的函数也非常多,而且不同的DBMS提供了相应的特殊函数.但是常用的共性函数大致可以分为以下几种: 函数类型 函数 数值函数 1.算术计算:+.-.*./ 2.数值处理:ABS()绝对值处理.P ...
- 更改collation批处理
DECLARE @zcreate_index_sql NVARCHAR(max); SET @zcreate_index_sql = N''; SELECT @zcreate_index_sql = ...
- mosquitto: error while loading shared libraries: libwebsockets.so.12: cannot open shared object file
错误描述: # mosquitto -c /etc/mosquitto/mosquitto.conf -dmosquitto: error while loading shared libraries ...
- JS获取当前时间戳及时间戳的转换
获取现在的Unix时间戳(Unix timestamp) Math.round(new Date().getTime()/1000) //getTime()返回数值的单位是毫秒 Unix时间戳(Un ...
- scratch学习研究心得_逐步更新
2019-10-30: Scratch对对象a克隆,不能选择克隆自己,这样可能下次一下子同时产生两个克隆体,要设置克隆a scratch3.0采用全新html5技术,图片和其他对象放大缩小,效果几乎不 ...
- 剑指offer之面试题2:实现Singleton模式
来源:剑指offer 这篇主要记录<剑指offer>书籍中的面试题2:实现Singleton模式 使用语言:C# 代码环境:VS2017 总共有5中解法,从前往后依次优化. 结构如下: 前 ...
- Winows上简单配置使用kafka(.net使用)
一.kafka环境配置 1.jdk安装 安装文件:http://www.oracle.com/technetwork/java/javase/downloads/index.html 下载JDK安装完 ...
- C#采集UVC摄像头画面并支持旋转和分辨率切换
在项目中,我们会需要控制uvc摄像头,采集其实时画面,或者对其进行旋转.目前市面上大多数USB摄像头都支持UVC协议.那么如何采集呢?当然是采用SharpCamera!因为SharpCamera支持对 ...