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 这题明显是一个方程组……可以推公式推出来…… 然而这太繁琐了 ...
随机推荐
- Golang(六)time 包的用法整理
1. 常用结构体 Duration:type Duration int64,时间长度,对应单位包括 Nanosecond(纳秒).Microsecond(微妙).Millisecond(毫秒).Sec ...
- shell(三)if流程控制
流程控制 if 流程控制 基本语法 单分支结构 if [];then fi 两分支结构 if [];then else fi 多分支结构 if [];then elif[];then elif[];t ...
- winform 通用自动更新程序
通用自动更新程序 主要功能: 1. 可用于 C/S 程序的更新,集成到宿主主程序非常简单和配置非常简单,或不集成到主程序独立运行. 2. 支持 HTTP.FTP.WebService等多种更新下载方式 ...
- Windows ----tasklist/taskkill
1) Tasklist命令详解 “Tasklist”命令是一个用来显示运行在本地或远程计算机上的所有进程的命令行工具,带有多个执行参数. 作用:结束一个或多个任务或进程.可以根据进程 ID 或图像名来 ...
- qbittorrent搜索插件合集
qbittorrent搜索 qbittorrent搜索一个很有特色的功能: 这里收集整理了一些公开网站的插件(Plugins for Public sites),并连 源py文件一起分享. qbitt ...
- HTML+CSS+JS综合练习(动态验证版)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vs2015下编译免费开源的jpeg库,ijg的jpeg.lib
vs2015下编译免费开源的jpeg库,ijg的jpeg.lib 1. 去Independent JPEG Group官网www.ijg.org下载jpegsrc,我下载的版本是jpegsrc9c.z ...
- 用友U9 UFSoft.UBF.Business.Session
Session的概念 在现在UBF中,Session的本意是work unit,即持久层的一个边界,非常轻,主要用作批量提交,并标识这次批量提交的边界,不涉及到事务等概念. 当前ISession可以通 ...
- 上传文件时用form.submit提交的时候在低版本的IE中报拒绝访问的错误
上传文件的时候,在IE7下总是传不了,但FireFox,IE11和Chrome下则可以上传.发现是form.submit();时出错了(“拒绝访问”). html代码为: <label oncl ...
- wps金山文档在线编辑--.Net 接入指南
一.申请成为服务商,对金山文档在线服务进行申请 ①进入官网 https://open.wps.cn/ ②申请后如下图,点击右下角的进入服务 ③申请成功后 ④数据回调URL一定是服务器地址,本次我使用的 ...