这是一个立方体的空间的路径搜索问题,若可达输出步数,不可达输出“NO ROUTE”

一道……课后题

输入的话我是按字符输入这个空间的

然后普通的bfs,一个方向数组,一个空间数组(因为只用一次,懒的再开一个,反正标记了,就是不能走的意思)引入某大佬的函数返回值做条件判重

需要注意的是,注意它的空间x,y,z轴分别怎么表示,我是通过建模型搞的(肯定有简单的方法)

下面是代码(西加加)

#include <iostream>
#include <string>
#include <queue>
#include <cstdio>
using namespace std;
bool mapp[10][10][10];
int a,b,c,d,e,f,n;
int dir[6][3]={{0,0,1},{0,1,0},{0,0,-1},{0,-1,0},{1,0,0},{-1,0,0}};
struct point{
int x,y,z,step;
point(int xx,int yy,int zz,int ss=0):x(xx),y(yy),z(zz),step(ss){}
point(){}
};
bool judge(point ipo){//区分或与与
if(ipo.x>=n||ipo.x<0)return 0;
if(ipo.y>=n||ipo.y<0)return 0;
if(ipo.z>=n||ipo.z<0)return 0;
if(mapp[ipo.z][ipo.y][ipo.x]==1)return 0;
return 1;
}
int bfs(){
queue<point>que;
que.push(point(a,b,c));
point now;
int tstep;
while(!que.empty()){
now=que.front();
que.pop();
if(now.x==d&&now.y==e&&now.z==f){
return now.step;
}
//if(judge(now)){mapp[now.z][now.y][now.x]=1; }
mapp[now.z][now.y][now.x]=1;
int tx,ty,tz;
tstep=now.step+1;
for(int t=0;t<6;t++){
tx=now.x+dir[t][2];
ty=now.y+dir[t][1];
tz=now.z+dir[t][0];
if(judge(point(tx,ty,tz)))que.push(point(tx,ty,tz,tstep));//判断次数相等,插入删除次数少
}
}
return -1;
}
int main()
{
string str;
int i,j,k;
char ch;
while(cin >> str >> n){
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
mapp[i][j][k]=0;
getchar();
for(i=0;i<n;i++){
for(j=0;j<n;j++){
for(k=0;k<n;k++){
ch=getchar();
if(ch=='X')mapp[i][j][k]=1;
}
getchar();
}
}
scanf("%d%d%d",&a,&b,&c);
scanf("%d%d%d",&d,&e,&f);
int ans=bfs();
cin >> str;
if(ans==-1)cout << "NO ROUTE" << endl;
else cout << n << ' ' << ans << endl;
}
return 0;
}
//对应关系
//x y z
//k j i
//a b c
//d e f

Asteroids!_poj2225的更多相关文章

  1. POJ 3041 Asteroids

     最小点覆盖数==最大匹配数 Asteroids Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12678 Accepted:  ...

  2. Asteroids(匈牙利算法入门)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16211   Accepted: 8819 Descri ...

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

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

  4. POJ 3041 Asteroids(最小点覆盖集)

                                                                      Asteroids Time Limit: 1000MS   Mem ...

  5. Asteroids (最小覆盖)

    题目很简单,但是需要推到出二分图最大匹配 = 最小覆盖 最小覆盖:证明过程http://blog.sina.com.cn/s/blog_51cea4040100h152.html Descriptio ...

  6. poj 3041 Asteroids(最小点覆盖)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  7. poj 3041 Asteroids (最大匹配最小顶点覆盖——匈牙利模板题)

    http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions ...

  8. HDU-1240 Asteroids! (BFS)这里是一个三维空间,用一个6*3二维数组储存6个不同方向

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

  9. POJ 3041 Asteroids 最小点覆盖 == 二分图的最大匹配

    Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape o ...

随机推荐

  1. 201771010135-杨蓉庆 实验一 软件工程准备—用Markdown写构建之法

    项目 内容 软件工程 https://www.cnblogs.com/nwnu-daizh   博客园  https://www.cnblogs.com/nwnu-daizh/p/12369881.h ...

  2. [lua]紫猫lua教程-命令宝典-L1-01-05. if判断结构

    L1[if]01. 简单的if判断结构 没什么说得 if得基本结构如下 xxx= ) then testlib.traceprint("1-100") ) then testlib ...

  3. Linux - XShell - alt 快捷键的设置

    1. 概述 命令行的 alt 快捷键可能会冲突 2. 环境 os win10 centos7 xshell xhell6 3. 场景 开启 centos7 虚拟机 在 win10 打开 xshell6 ...

  4. yii2之ActiveRecord 模型

          Active Record 模型是一种设计模式,用面向对象的方式抽象地访问数据的模式.在 Yii2 中,每一个 Active Record 模型对象的实例是 yii\db\ActiveRe ...

  5. 基于maven+java+TestNG+httpclient+poi+jsonpath+ExtentReport的接口自动化测试框架

    接口自动化框架 项目说明 本框架是一套基于maven+java+TestNG+httpclient+poi+jsonpath+ExtentReport而设计的数据驱动接口自动化测试框架,TestNG ...

  6. 搭建 VUE + NODE.JS + ElementUI 学习过程中问题总结

    1.exports 和 module.exports require 用来加载代码,而 exports 和 module.exports 则用来导出代码. module.exports 初始值为一个空 ...

  7. stm32控制步进电机加减速

    实习公司项目需要控制步进电机,电机方面主要包括控制运动.加减速.限位.下面介绍一下在电机控制方面的心得,由于对于电机的控制不需要很精确,并且自身能力有限,相比于大牛有很大的差距. 1.需要实现的功能 ...

  8. C:作用域

    作用域 C语言变量的作用域分为: 代码块作用域(代码块是{}之间的一段代码) 函数作用域 文件作用域 局部变量 局部变量也叫auto自动变量(auto可写可不写),一般情况下代码块{}内部定义的变量都 ...

  9. 吴裕雄 python 人工智能——基于Mask_RCNN目标检测(2)

    import os import sys import itertools import math import logging import json import re import random ...

  10. C++中使用sstream进行类型转换(数字字符串转数字、数字转数字字符串)

    1.sstream知识 sstream即字符串流.在使用字符串流sstream时,需要先引入相应的头文件 "#include <sstream>" 基本操作 // 引入 ...