10146_Overfencing

2022-5-16 18:16| 发布者: Hocassian| 查看: 94| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504598917400-Problem List-采集的数据-后羿采集器.html

Pro.ID

10146

Title

Overfencing

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10146

AC

37

Submit

102

Ratio

36.27%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/131072 K (Java/Others)
  • 描述

    Farmer John went crazy and created a huge maze of fences out in a field. Happily, he left out two fence segments on the edges, and thus created two "exits" for the maze. Even more happily, the maze he created by this overfencing experience is a 'perfect' maze: you can find a way out of the maze from any point inside it.

    Given W (1 ≤ W ≤ 38), the width of the maze; H (1 ≤ H ≤ 100), the height of the maze; 2×H+1 lines with width 2×W+1 characters that represent the maze in a format like that shown later --- then calculate the number of steps required to exit the maze from the 'worst' point in the maze (the point that is 'farther' from either exit even when walking optimally to the closest exit). Of course, cows walk only parallel or perpendicular to the x-y axes; they do not walk on a diagonal. Each move to a new square counts as a single unit of distance (including the move "out" of the maze.

    Here's what one particular W=5, H=3 maze looks like:

     +-+-+-+-+-+
     |         |
     +-+ +-+ + +
     |     | | |
     + +-+-+ + +
     | |     |  
     +-+ +-+-+-+

    Fenceposts appear only in odd numbered rows and and odd numbered columns (as in the example). The format should be obvious and self explanatory. Each maze has exactly two blank walls on the outside for exiting.

    输入

    Multiple test case. For each case:

    Line 1:    W and H, space separated

    Lines 2 through 2×H+2:     2×W+1 characters that represent the maze

    输出

    Description

    Farmer John went crazy and created a huge maze of fences out in a field. Happily, he left out two fence segments on the edges, and thus created two "exits" for the maze. Even more happily, the maze he created by this overfencing experience is a 'perfect' maze: you can find a way out of the maze from any point inside it.

    Given W (1 ≤ W ≤ 38), the width of the maze; H (1 ≤ H ≤ 100), the height of the maze; 2×H+1 lines with width 2×W+1 characters that represent the maze in a format like that shown later --- then calculate the number of steps required to exit the maze from the 'worst' point in the maze (the point that is 'farther' from either exit even when walking optimally to the closest exit). Of course, cows walk only parallel or perpendicular to the x-y axes; they do not walk on a diagonal. Each move to a new square counts as a single unit of distance (including the move "out" of the maze.

    Here's what one particular W=5, H=3 maze looks like:

     +-+-+-+-+-+
     |         |
     +-+ +-+ + +
     |     | | |
     + +-+-+ + +
     | |     |  
     +-+ +-+-+-+

    Fenceposts appear only in odd numbered rows and and odd numbered columns (as in the example). The format should be obvious and self explanatory. Each maze has exactly two blank walls on the outside for exiting.

    Input

    Multiple test case. For each case:

    Line 1:    W and H, space separated

    Lines 2 through 2×H+2:     2×W+1 characters that represent the maze

    Output

    For each case, output a single integer on a single output line. The integer specifies the minimal number of steps that guarantee a cow can exit the maze from any possible point inside the maze.

    Sample Input

    5 3
    +-+-+-+-+-+
    |         |
    +-+ +-+ + +
    |     | | |
    + +-+-+ + +
    | |     |  
    +-+ +-+-+-+

    Sample Output

    9

    Hint

    The lower left-hand corner is *nine* steps from the closest exit.

    Source

    样例输入

    5 3
    +-+-+-+-+-+
    |         |
    +-+ +-+ + +
    |     | | |
    + +-+-+ + +
    | |     |  
    +-+ +-+-+-+

    样例输出

    9

    提示

    The lower left-hand corner is *nine* steps from the closest exit.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部