【POJ 3322】 Bloxorz I
【题目链接】
http://poj.org/problem?id=3322
【算法】
广度优先搜索
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 510 int i,j,n,m;
char mp[MAXN][MAXN]; const int dx[] = {,,-,};
const int dy[] = {-,,,};
const int nx[][] = {{,,-,},{,,-,},{,,-,}};
const int ny[][] = {{-,,,},{-,,,},{-,,,}};
const int nxt[][] = {{,,,},{,,,},{,,,}}; struct info
{
int x,y;
int state;
};
inline bool ok(int x,int y)
{
return x >= && x <= n && y >= && y <= m;
}
inline bool check(int x,int y,int state)
{
if (!ok(x,y)) return false;
if (state == && (mp[x][y] == '#' || mp[x][y] == 'E')) return false;
if (state == && (!ok(x,y+) || mp[x][y] == '#' || mp[x][y+] == '#')) return false;
if (state == && (!ok(x+,y) || mp[x][y] == '#' || mp[x+][y] == '#')) return false;
return true;
}
inline void bfs()
{
int i,j,k,tx,ty,ts;
info s,e,cur;
queue< info > q;
static int dist[MAXN][MAXN][];
while (!q.empty()) q.pop();
for (i = ; i <= n; i++)
{
for (j = ; j <= m; j++)
{
for (k = ; k < ; k++)
{
dist[i][j][k] = -;
}
}
}
for (i = ; i <= n; i++)
{
for (j = ; j <= m; j++)
{
if (mp[i][j] == 'X')
{
s.x = i;
s.y = j;
s.state = ;
for (k = ; k < ; k++)
{
tx = i + dx[k];
ty = j + dy[k];
if (ok(tx,ty) && mp[tx][ty] == 'X')
{
s.x = min(i,tx);
s.y = min(j,ty);
if (k < ) s.state = ;
else s.state = ;
}
}
}
if (mp[i][j] == 'O')
{
e.x = i;
e.y = j;
e.state = ;
}
}
}
dist[s.x][s.y][s.state] = ;
q.push(s);
while (!q.empty())
{
cur = q.front();
q.pop();
for (i = ; i < ; i++)
{
tx = cur.x + nx[cur.state][i];
ty = cur.y + ny[cur.state][i];
ts = nxt[cur.state][i];
if (check(tx,ty,ts) && dist[tx][ty][ts] == -)
{
q.push((info){tx,ty,ts});
dist[tx][ty][ts] = dist[cur.x][cur.y][cur.state] + ;
if (tx == e.x && ty == e.y && ts == e.state)
{
printf("%d\n",dist[tx][ty][ts]);
return;
}
}
}
}
printf("Impossible\n");
} int main()
{ while (scanf("%d%d",&n,&m) && n && m)
{
getchar();
for (i = ; i <= n; i++)
{
for (j = ; j <= m; j++)
{
mp[i][j] = getchar();
}
getchar();
}
bfs();
} return ; }
【POJ 3322】 Bloxorz I的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- js 性能调试
今天有幸偶遇我早就神往已久的性能调试问题. 原来js调试工具里面有可以记录每个方法的执行时间的功能,站在此功能的肩膀上就可以对自己的程序性能.瓶颈了如指掌,就可以针对性的,瞄准目标,斩草除根,以绝后患 ...
- CSS3 background-origin 属性
CSS3 background-origin 属性 padding-box 背景图像相对于内边距框来定位. border-box 背景图像相对于边框盒来定位. content-box 背景图像相对于内 ...
- jboss-eap-6.2修改端口号
最近要改版一个项目,用来配合日常工作使用,需要在服务器上放多个jboss,那么就需要修改jboss的端口,如果服务器上配置了JBOSS_HOME,需要先删除,否则配置修改不会生效,会依然用老的jbos ...
- PHP 之微信小程序支付封装
<?php /** * Created by PhpStorm. * User: yangs * Date: 2019/4/26 * Time: 14:28 */ class WeixinPay ...
- 戴尔14G服务器用H740P配置阵列
公司采购了几台dell r740机器.做阵列的方式跟之前ctrl+r有很大改动. 戴尔14G机器已经面世一段时间了,14G的机器使用过后都能发现器性能比上一代机器提升了很多,今天给大家带来戴尔14代服 ...
- BFS入门篇——RQNOJ195&&335
PID195 / 校园迷宫☆ 从x,y走到去q,w的最小步数,限制是有的点可走,有的点不可走,BFS嘛. #include<bits/stdc++.h> using namespace s ...
- 29. 误拼写时的fuzzy模糊搜索技术
搜索的时候,可能输入的搜索文本会出现误拼写的情况,这时就需要es为我们进行智能纠错 比如有两个文档: doc1: hello world doc2: hello java 现在要搜索:hall ...
- TortoiseGit配置密钥的方法
TortoiseGit 使用扩展名为ppk的密钥,而不是ssh-keygen生成的rsa密钥.使用命令ssh-keygen -C "邮箱地址" -t rsa产生的密钥在Tortoi ...
- ISNUMERIC()检测是否为数字
ISNUMERIC ( expression )当输入表达式得数为一个有效的整数.浮点数.money 或 decimal 类型,那么 ISNUMERIC 返回 1:否则返回 0.返回值为 1 确保可以 ...
- hdu2001 计算两点间的距离【C++】
计算两点间的距离 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...