AOJ.866 飞越原野 (三维BFS)

题意分析

点我挑战题目

相比于普通的BFS,要多一维来记录当前剩余的体力。而且还要额外的一层循环来处理,飞过的路程。

代码总览

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#define INF 0x3f3f3f3f
#define nmax 200
#define MEM(x) memset(x,0,sizeof(x))
using namespace std;
bool visit[nmax][nmax][nmax],isfind = false;
char mp[nmax][nmax];
struct nod{
int x,y,e;
}node[nmax];
int m,n,o,ans;
int spx[] = {0,1,0,-1};
int spy[] = {1,0,-1,0};
bool check(int x, int y, int e)
{
if(x<0 || x >= m || y<0 || y>=n || mp[x][y] =='L' || visit[x][y][e] == true)
return false;
else
return true;
}
void bfs()
{
nod temp;
temp.x = 0; temp.y = 0; temp.e = o;
visit[temp.x][temp.y][temp.e] = true;
queue<nod> q;
if(!q.empty()) q.pop();
q.push(temp);
ans = 0;
while(!q.empty()){
int nowsize = q.size();
while(nowsize--){
nod tep = temp = q.front();
q.pop();
// get final or not
if(tep.x == m-1 && tep.y == n-1){
isfind = true;
break;
}
for(int i = 0 ;i<4;++i){
tep.x =temp.x + spx[i];
tep.y =temp.y + spy[i];
if(check(tep.x,tep.y,tep.e)){
visit[tep.x][tep.y][tep.e] = true;
q.push(tep);
}
}
for(int i = 0; i<4;++i){
for(int j = 1; j<=temp.e;++j){
tep.x = temp.x + spx[i] *j;
tep.y = temp.y + spy[i] *j;
tep.e = temp.e - j;
if(check(tep.x,tep.y,tep.e)){
visit[tep.x][tep.y][tep.e] = true;
q.push(tep);
}
}
}
}
if(isfind) break;
ans++;
}
}
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d %d %d",&m,&n,&o) != EOF){
MEM(visit);
isfind = false;
for(int i = 0; i<m;++i)
scanf("%s",mp[i]);
bfs();
if(isfind) printf("%d\n",ans);
else printf("impossible\n");
}
return 0;
}

AOJ.866 飞越原野 (三维BFS)的更多相关文章

  1. 飞跃原野(三维bfs)

    Problem Description 勇敢的法里奥出色的完成了任务之后,正在迅速地向自己的基地撤退.但由于后面有着一大群追兵,所以法里奥要尽快地返回基地,否则就会被敌人逮住. 终于,法里奥来到了最后 ...

  2. SDUT OJ 1124 飞越原野 (三维BFS练习)

    飞跃原野 nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit5000ms Memory Limit 65536K ...

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

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

  4. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  5. POJ 2049— Finding Nemo(三维BFS)10/200

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...

  6. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  7. AOJ.865 青铜莲花池 (BFS)

    AOJ.865 青铜莲花池 (BFS) 题意分析 典型的BFS 没的说 代码总览 #include <iostream> #include <cstdio> #include ...

  8. SDUT 1124-飞跃荒野(三维BFS)

    飞跃原野 Time Limit: 5000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 勇敢的法里奥出色的完毕了任务之后.正在迅速地向自己的基地撤退.但因为 ...

  9. AOJ 0121: Seven Puzzle【BFS】

    From: AOJ 0121 思路:与前几题的bfs不同,这次的bfs没有明确的移动对象,看似任意一个数都可以当成对象移动.这时我们只需要抓住一个格子就行,比如我们把0作为移动对象,那么0在地图中漫游 ...

随机推荐

  1. word record 3

    word record 3 tabloid : a half size page of a newspaper, or a newspaper or magazine with short, exci ...

  2. Uncaught Error: code length overflow. (1604>1056)

    解决方法来源~~~https://blog.csdn.net/arrowzz/article/details/80656510 二维码生成时,如果长度太长会有异常: Uncaught Error: c ...

  3. Angualr6访问API

    参照 草根专栏- ASP.NET Core + Ng6 实战: https://v.qq.com/x/page/a0769armuui.html 1.environment.ts 添加apiUrlBa ...

  4. 孤荷凌寒自学python第八十五天配置selenium并进行模拟浏览器操作1

    孤荷凌寒自学python第八十五天配置selenium并进行模拟浏览器操作1 (完整学习过程屏幕记录视频地址在文末) 要模拟进行浏览器操作,只用requests是不行的,因此今天了解到有专门的解决方案 ...

  5. (转) GEM透视阴影贴图

    转载:小道 透视阴影贴图(Perspective Shadow Maps, PSMs)是由Stamminger和Drettakis在 SIGGRAPH 2002上提出的一种阴影贴图(Shadow Ma ...

  6. Java进阶知识点:更优雅地关闭资源 - try-with-resource

    一.背景 我们知道,在Java编程过程中,如果打开了外部资源(文件.数据库连接.网络连接等),我们必须在这些外部资源使用完毕后,手动关闭它们.因为外部资源不由JVM管理,无法享用JVM的垃圾回收机制, ...

  7. 【shell 练习2】产生随机数的方法总结

    一.产生随机数 ()RANDOM 产生随机数 [root@localhost ~]# echo $RANDOM [root@localhost ~]# )) #想要生成八个随机数,随便加一个八位的数字 ...

  8. 关于Filter中ServletRequest强转HttpServletRequest问题

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOE ...

  9. Leetcode - 461. Hamming Distance n&=(n-1) (C++)

    1. 题目链接:https://leetcode.com/problems/hamming-distance/description/ 2.思路 常规做法做完看到评论区一个非常有意思的做法.用了n&a ...

  10. POJ 2455 Secret Milking Machine(最大流+二分)

    Description Farmer John is constructing a new milking machine and wishes to keep it secret as long a ...