• 嘻嘻


    NYOJ

    描述    Shining Knight is the embodiment of justice and he has a very sharp sword can even cleave wall. Many bad guys are dead on his sword.

    One day, two evil sorcerer cgangee and Jackchess decided to give him some colorto see. So they kidnapped Shining Knight's beloved girl--Miss Ice! They built a M x N maze with magic and shut her up in it.

    Shining Knight arrives at the maze entrance immediately. He can reach any adjacent empty square of four directions -- up, down, left, and right in 1 second. Or cleave one adjacent wall in 3

    seconds, namely,turn it into empty square. It's the time to save his goddess! Notice: Shining Knight won't leave the maze before he find Miss Ice.

    输入   The input consists of blocks of lines. There is a blank line between two blocks.

    The first line of each block contains two positive integers M <= 50 and N <= 50separated by one space. In each of the next M lines there is a string of length N contentsO and #.

    O represents empty squares. # means a wall.

    At last, the location of Miss Ice, ( x, y ). 1 <= x <= M, 1 <= y <= N.

    (Shining Knight always starts at coordinate ( 1, 1 ). Both Shining and Ice's locationguarantee not to be a wall.)

    输出

    The least amount of time Shining Knight takes to save hisgoddess in one line.

    样例输入

    3 5
    O####
    #####
    #O#O#
    3 4
    

    样例输出

    14
    ---------------------------------我是题目和分析的 分隔符------------------------------------------------
    分析:输入有三部分 第一行 有两个数字分别代表下面几行(除了最后一行)的行数和列数 最后一行代表的是 公主的位置(坐标) 中间的几行有"#"和"O"他们分别代表的意思是 "#"中间是一个屋子四面都是墙 "O"的意思是
    四面都是空的(没有墙) 王子手里的宝剑 在三个单位时间内 可以 打破一堵墙 王子从一个房间 跨越到另一个房间需要 1个单位时间 (王子只能 在上下左右 这四个方向上移动 ) 现在给你 上述信息 你需要求出来王子 在用时 最短的情况下 几分钟可以将 公主解救出来 .
    -----------------------------------好激动 应该要用到 搜索了------------------------------------------------
    下面附上 数据结构视频 (讲的是 DFS 和BFS 在图中的应用 )

  • 相关阅读:
    LeetCode#160-Intersection of Two Linked Lists-相交链表
    LeetCode#2-Add Two Numbers-两数相加
    LeetCode#141-Linked List Cycle-环形链表
    LeetCode#66-Plus One-加一
    LeetCode#35-Search Insert Position-搜索插入位置
    LeetCode#203-Remove Linked List Elements-移除链表元素
    基姆拉尔森公式
    [leetcode] 树(Ⅲ)
    常用算法合集(一)
    离散数学 II(最全面的知识点汇总)
  • 原文地址:https://www.cnblogs.com/A-FM/p/5215939.html
Copyright © 2020-2023  润新知