AOJ.866 飞越原野 (三维BFS)
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)的更多相关文章
- 飞跃原野(三维bfs)
Problem Description 勇敢的法里奥出色的完成了任务之后,正在迅速地向自己的基地撤退.但由于后面有着一大群追兵,所以法里奥要尽快地返回基地,否则就会被敌人逮住. 终于,法里奥来到了最后 ...
- SDUT OJ 1124 飞越原野 (三维BFS练习)
飞跃原野 nid=24#time" title="C.C++.go.haskell.lua.pascal Time Limit5000ms Memory Limit 65536K ...
- hdu 1240:Asteroids!(三维BFS搜索)
Asteroids! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2049— Finding Nemo(三维BFS)10/200
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u013497151/article/details/29562915 海底总动员.... 这个题開始 ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- AOJ.865 青铜莲花池 (BFS)
AOJ.865 青铜莲花池 (BFS) 题意分析 典型的BFS 没的说 代码总览 #include <iostream> #include <cstdio> #include ...
- SDUT 1124-飞跃荒野(三维BFS)
飞跃原野 Time Limit: 5000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 勇敢的法里奥出色的完毕了任务之后.正在迅速地向自己的基地撤退.但因为 ...
- AOJ 0121: Seven Puzzle【BFS】
From: AOJ 0121 思路:与前几题的bfs不同,这次的bfs没有明确的移动对象,看似任意一个数都可以当成对象移动.这时我们只需要抓住一个格子就行,比如我们把0作为移动对象,那么0在地图中漫游 ...
随机推荐
- JMeter性能测试的基础知识和个人理解
JMeter性能测试的基础知识和个人理解 1. JMeter的简介 JMeter是Apache组织开发的开源项目,设计之初是用于做性能测试的,同时它在实现对各种接口的调用方面做的比较成熟,因此,常 ...
- 第十五届北京师范大学程序设计竞赛现场决赛题解&源码(A.思维,C,模拟,水,坑,E,几何,思维,K,字符串处理)
#include <bits/stdc++.h> using namespace std; int main() { int T,n,a,b; while(cin>>T) { ...
- 6.2 element和elements
为什么这个要单独拿出来说,因为我在很多群里面看见很多人不能区分这个! 因为之前的包有点问题,另外后续还会更换app,因为部分app可能没有符合的案例场景,我需要找到那个场景给大家做个实例..便于大家跟 ...
- Unity Shader学习笔记 - 用UV动画实现沙滩上的泡沫
这个泡沫效果来自远古时代的Unity官方海岛Demo, 原效果直接复制3个材质球在js脚本中做UV动画偏移,这里尝试在shader中做动画并且一个pass中完成: // Upgrade NOTE: r ...
- (转)Shadow Mapping
原文:丢失,十分抱歉,这篇是在笔记上发现的.SmaEngine 阴影和级联部分是模仿UE的结构设计 This tutorial will cover how to implement shadow ...
- Java进阶知识点:不可变对象与并发
一.String的不可变特性 熟悉Java的朋友都知道,Java中的String有一个很特别的特性,就是你会发现无论你调用String的什么方法,均无法修改this对象的状态.当确实需要修改Strin ...
- 从hive导入到oracle(Hcatalog)
1.使用catalog的情况下: sqoop export --table tableName2 \ #oracle表 --connect jdbc:oracle:thin:@127.0.0.1:15 ...
- POJ 1921 Paper Cut(计算几何の折纸问题)
Description Still remember those games we played in our childhood? Folding and cutting paper must be ...
- ZOJ 2532 Internship(最大流找关键割边)
Description CIA headquarter collects data from across the country through its classified network. Th ...
- 简单DP
1.一只小蜜蜂 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. Input输入数据的第一行是一个整数N,表 ...