AgreenHay 2022-01-20 10:31 采纳率: 0%
浏览 24

poj 2251 答案错误 给出的测试样例已通过 求一个反例

题目http://poj.org/problem?id=2251

Description

You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.

Is an escape possible? If yes, how long will it take?
Input

The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
L is the number of levels making up the dungeon.
R and C are the number of rows and columns making up the plan of each level.
Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.
Output

Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
Escaped in x minute(s).

where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!


Sample Input

3 4 5
S . . . .
. # # # .
. # # . .
# # # . #

# # # # #
# # # # #
# # . # #
# # . . .

# # # # #
# # # # #
# . # # #
# #  # #E

1 3 3
S # #
#E #
# # #

0 0 0
Sample Output

Escaped in 11 minute(s).
Trapped!

就是一道三维迷宫的题 先输入有几层 然后输入长 宽 S是起点 E是终点 求最短时间

#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <sstream>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

char arr[100][100][100];//迷宫
int arr1[100][100][100];//标记
int zyx[6][3]={ {1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1} };
struct point
{
    int x;
    int y;
    int z;
    int step;
};
void chushi(int z, int x, int y)
{
    for (int i = 0; i <= z+1; i++)//输入 
        for (int j = 0; j <= y+1; j++)
            for (int k = 0; k <= x+2; k++)
                arr[i][j][k]='#';
}
queue<point> duilie;
int main()
{
    int n;
    int m, l;
    point start;
    point end;
    while (cin >> n >> l >> m)
    {
        int sign = 0;
        if (n == 0 && l == 0 && m == 0)
            return 0;
        chushi(n, l, m);
        for (int i = 1; i <= n; i++)//输入 
            for (int j = 1; j <= l; j++)
                for (int k = 1; k <= m; k++)
                    cin >> arr[i][j][k];
        for (int i = 1; i <= n; i++)//输入 
            for (int j = 1; j <= l; j++)
                for (int k = 1; k <= m; k++)
                {
                    if (arr[i][j][k] == 'S')
                    {
                        start.z = i;
                        start.y = j;
                        start.x = k;
                        start.step = 0;
                    }
                    if (arr[i][j][k] == 'E')
                    {
                        end.z = i;
                        end.y = j;
                        end.x = k;
                        arr[i][j][k] = '.';
                    }
                }
        duilie.push(start);
        while (!duilie.empty())//先上 平面 后下
        {
            int z = duilie.front().z;
            int x = duilie.front().x;
            int y = duilie.front().y;
            if (z == end.z && x == end.x && y == end.y)
            {
                sign = 1;
                cout << "Escaped in " << duilie.front().step << " minute(s).\n";
                break;
            }
            for (int i = 0; i < 6; i++)
            {
                int x1 = x + zyx[i][2];
                int y1 = y + zyx[i][1];
                int z1 = z + zyx[i][0];
                if (arr[z1][y1][x1] == '.' && arr1[z1][y1][x1] == 0)
                {
                    point tmp;
                    tmp.x = x1;
                    tmp.y = y1;
                    tmp.z = z1;
                    tmp.step = duilie.front().step + 1;
                    arr1[z1][y1][x1] = 1;
                    duilie.push(tmp);
                }
            }
            duilie.pop();
        }
        if (sign == 0)
            cout << "Trapped!\n";
    }
    
    return 0;
}
  • 写回答

1条回答 默认 最新

  • [PE]经典八炮 2022-01-20 10:41
    关注

    题目发出来啊

    评论

报告相同问题?

问题事件

  • 修改了问题 1月20日
  • 创建了问题 1月20日

悬赏问题

  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决