分析:一个n*m的矩阵,每个格子有12个状态,每次按一次,每个格子转90度,所以整个矩阵只有4种状态,然后爆搜就好了

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <cmath>
#include <queue>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int N=1e3+;
struct Node{
int t,x,y;
};
queue<Node>q;
char c[N][N];
int s[][N][N],n,m;
char p[]="0+-|^><vLRUD*";
int a[]={,,,,,,,,,,,,};
int b[]={,,,,,,,,,,,,};
int dp[][N][N];
bool judgel(int x){
if(x==||x==||x==||x==||x==||x==)
return true;
return false;
}
bool judger(int x){
if(x==||x==||x==||x==||x==||x==)
return true;
return false;
}
bool judgeu(int x){
if(x==||x==||x==||x==||x==||x==)
return true;
return false;
}
bool judged(int x){
if(x==||x==||x==||x==||x==||x==)
return true;
return false;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i)
scanf("%s",c[i]+);
for(int i=;i<=n;++i)
{
for(int j=;j<=m;++j)
{
for(int k=;k<=;++k)
if(c[i][j]==p[k])
{
s[][i][j]=a[k];
break;
}
}
}
for(int k=;k<=;++k)
{
for(int i=;i<=n;++i)
{
for(int j=;j<=m;++j)
{
s[k][i][j]=b[s[k-][i][j]];
}
}
}
Node st,aim;
scanf("%d%d%d%d",&st.x,&st.y,&aim.x,&aim.y);
memset(dp,-,sizeof(dp));
st.t=;
q.push(st);dp[][st.x][st.y]=;
int ans=INF;
while(!q.empty()){
Node u=q.front();
q.pop();
if(u.x==aim.x&&u.y==aim.y){
break;
}
Node e=u;e.t=(e.t+)%;
if(dp[e.t][e.x][e.y]==-){
dp[e.t][e.x][e.y]=dp[u.t][e.x][e.y]+;
q.push(e);
}
if(u.y>&&judgel(s[u.t][u.x][u.y])&&judger(s[u.t][u.x][u.y-])){
if(dp[u.t][u.x][u.y-]==-){
e=u;--e.y;
dp[e.t][e.x][e.y]=dp[u.t][u.x][u.y]+;
q.push(e);
}
}
if(u.y<m&&judger(s[u.t][u.x][u.y])&&judgel(s[u.t][u.x][u.y+])){
if(dp[u.t][u.x][u.y+]==-){
e=u;++e.y;
dp[e.t][e.x][e.y]=dp[u.t][u.x][u.y]+;
q.push(e);
}
}
if(u.x>&&judgeu(s[u.t][u.x][u.y])&&judged(s[u.t][u.x-][u.y])){
if(dp[u.t][u.x-][u.y]==-){
e=u;--e.x;
dp[e.t][e.x][e.y]=dp[u.t][u.x][u.y]+;
q.push(e);
}
}
if(u.x<n&&judged(s[u.t][u.x][u.y])&&judgeu(s[u.t][u.x+][u.y])){
if(dp[u.t][u.x+][u.y]==-){
e=u;++e.x;
dp[e.t][e.x][e.y]=dp[u.t][u.x][u.y]+;
q.push(e);
}
}
}
for(int i=;i<;++i)
if(dp[i][aim.x][aim.y]!=-){
ans=min(dp[i][aim.x][aim.y],ans);
}
if(ans==INF)ans=-;
printf("%d\n",ans);
return ;
}

codeforces 676D Theseus and labyrinth BFS搜索的更多相关文章

  1. CodeForces 676D Theseus and labyrinth

    最短路. $dis[i][j][k]$记录到点$(i,j)$,门的状态为$k$时的最短路.转移的时候有$8$种方案,即直接走向周围四个点,或者进行旋转.比较烦的是判断两个相邻的点在状态$k$下是否连通 ...

  2. Codeforces Round #354 (Div. 2) D. Theseus and labyrinth bfs

    D. Theseus and labyrinth 题目连接: http://www.codeforces.com/contest/676/problem/D Description Theseus h ...

  3. hdu--1026--Ignatius and the Princess I(bfs搜索+dfs(打印路径))

    Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. CodeForces 540C Ice Cave (BFS)

    http://codeforces.com/problemset/problem/540/C       Ice Cave Time Limit:2000MS     Memory Limit:262 ...

  5. hdu 1240:Asteroids!(三维BFS搜索)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. hiho_1139_二分+bfs搜索

    题目 给定N个点和M条边,从点1出发,到达点T.寻找路径上边的个数小于等于K的路径,求出所有满足条件的路径中最长边长度的最小值. 题目链接:二分     最小化最大值,考虑采用二分搜索.对所有的边长进 ...

  7. Codeforces 301_div.2_Ice Cave(BFS走冰块)

    Ice Cave Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Descripti ...

  8. BFS搜索

    参考博客:[算法入门]广度/宽度优先搜索(BFS) 适用问题:一个解/最优解 重点:我们怎么运用队列?怎么记录路径? 假设我们要找寻一条从V0到V6的最短路径.(明显看出这条最短路径就是V0-> ...

  9. Horse Pro(带负坐标的bfs搜索)

    Horse Pro bfs搜索,但图中存在负值坐标,两种方法解决. 用数组标记,将原点设为300,300 用map标记 http://oj.jxust.edu.cn/contest/Problem?i ...

随机推荐

  1. 如何使用PHP实现一个WebService

    WSDL WSDL(网络服务描述语言,Web Services Description Language)是一门基于 XML 的语言,用于描述 Web Services 以及如何对它们进行访问.这种文 ...

  2. uva 567

    Floyd 算法   就输入麻烦点 #include <iostream> #include <cstring> #include <cstdlib> #inclu ...

  3. spoj 297

    就是对距离进行二分找最大值 .... #include <cstring> #include <cstdio> #include <algorithm> #incl ...

  4. install Nagios on Unbuntu Unix

    Ubuntu Quickstart Up To: ContentsSee Also: Quickstart Installation Guides, Security Considerations I ...

  5. 【leetcode】Word Ladder (hard) ★

    Given two words (start and end), and a dictionary, find the length of shortest transformation sequen ...

  6. Tornado,了解一下

    多了解不一样的PYTHON框架,对深入了解DJANGO,总是有帮助的. import textwrap import tornado.httpserver import tornado.ioloop ...

  7. poj The Clocks 高斯消元

    由于数据量不大,所以这题有很多解法. 我用的是高斯消元化为逆矩阵解决的…… 代码如下: #include<stdio.h> #include<iostream> using n ...

  8. sizeof运算符来获取各种数据类型在内存中所占字节数--gyy整理

    C++并没有规定各种数据类型在内存中的存储大小,依赖于不同的编译器的不同而不同,要想获知当前编译器对各种数据类型分配的大小,可以通过sizeof运算符来获取. 使用方法1: sizeof(数据类型) ...

  9. Nginx/Apache日志分析脚本

    1,查看apache进程: ps aux | grep httpd | grep -v grep | wc -l 2,查看80端口的tcp连接: netstat -tan | grep "E ...

  10. Linux的终端与进程

    原文链接:http://os.51cto.com/art/201104/256477.htm Linux的普通进程(守护进程除外) 是终端的子进程,进程的存在要依赖终端为其提供空间包括标准输入.标准输 ...