zoukankan      html  css  js  c++  java
  • HDU 1240 Asteroids! 解题报告

    //这道题做完我只有 三个感受  第一:坑; 第二 : 坑! 第三:还是坑!

    咳咳  言归正传  WA了无数次之后才发现是输入进去时坐标时z, y, x的顺序输入的

    题解   :  类似胜利大逃亡 只不过给你了起始坐标和终点坐标, 让你输出到达目标点所需最少步数;

    输出时第一个输出时是START读入的map大小值n;第二个是所求步数

    //细节:

    1.读入:   读入时分别两次%S把没用的START 和 END读取掉;

    2.输出时输出 三维坐标大小值n, 以及步数;

    3.输入进去时开始点和结束点坐标都是z, y, x的顺序输入的!!!!!!!多加感叹号 因为这是这道题最坑的地方。

    代码奉上:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #define N 15
    using namespace std;

    typedef struct node
    {
    int x, y, z;
    int step;
    }ND;

    ND s, e;
    int dir[6][3] = {0,0,1, 0,1,0, 1,0,0, 0,0,-1, 0,-1,0, -1,0,0};
    char maps[N][N][N];
    char str[10];
    int n;

    void inPut()
    {
    int i, j;
    for(i = 0; i < n; i++)
    for(j = 0; j < n; j++)
    scanf("%s", maps[i][j]);

    scanf("%d %d %d", &s.z, &s.y, &s.x);
    scanf("%d %d %d", &e.z, &e.y, &e.x);
    scanf("%s", str);
    }

    void BFS()
    {
    int x, y, z, i;
    ND v;
    maps[s.x][s.y][s.z] = 'X';

    queue<ND>q;
    q.push(s);

    while(!q.empty())
    {
    s = q.front();
    q.pop();
    if(s.x == e.x && s.y == e.y && s.z == e.z)
    {
    printf("%d %d\n", n, s.step);
    return;
    }
    for(i = 0; i < 6; i++)
    {
    x = s.x + dir[i][0];
    y = s.y + dir[i][1];
    z = s.z + dir[i][2];
    if(x >= 0 && x < n && y >= 0 && y < n && z >= 0 && z < n && maps[x][y][z] == 'O')
    {
    maps[x][y][z] = 'X';
    v = {x, y, z, s.step + 1};
    q.push(v);
    }
    }
    }

    printf("NO ROUTE\n");
    }

    int main()
    {
    while(scanf("%s%d", str, &n) != EOF)
    {
    memset(maps, 0, sizeof(maps));
    inPut();
    BFS();
    }
    }

  • 相关阅读:
    SEO(搜索引擎优化)已死
    C#与Java的详细比较(全)
    回眸·预言:Google媒体,称霸在2014 (转载)& 2015 update
    转载:Google calendar预览
    一个开源的ESB(企业服务总线) Celtix
    未来网虫生活图景
    今年圣诞节google标的意思
    我的生活质量
    Google Reader的午夜维护信息
    SNS网站应该更加自然
  • 原文地址:https://www.cnblogs.com/wangyuhao/p/4451560.html
Copyright © 2011-2022 走看看