编程介的小学生 2017-10-05 01:32 采纳率: 20.5%
浏览 853
已采纳

Right-Hand Rule

Description

A common approach to navigating garden mazes is to, upon entry to the maze, to place one's hand upon the wall to right of the entrance, and then to walk forward, keeping that right hand in contact with a wall at all times.

It's well known that this technique allows one to pass through one-entrance, one-exit mazes, but it does not always suffice with mazes where one is supposed to reach some goal location or locations in the interior of the maze.

Write a program to read in a description of a maze marked with a goal location and one or more entrances, and to determine whether the goal can be found by applying the right-hand rule until the goal is found or until the rule causes you to pass outside the maze through one of the entrances.

We assume that people walking through the maze will look around as they do so. Consequently, a goal is considered to have been ``found" if the person steps directly onto that location or reaches any position with an unimpeded view to the goal along a vertical or horizontal line.
Input

Input consists of one or more mazes. Each maze begins with a line containing two integers, W and h , denoting the width and the height of the maze. End of input is indicated when either of these values is less than 3.

This is followed by h lines of input. In each of these lines, only the first w characters are significant. If the input line contains fewer than w characters, you should treat the missing characters as `X'.

The interpretation of the characters in these lines is as follows:
' ' denotes an open space
'G' is an open space representing a goal location - there will be exactly one of these in any maze.
'X' denotes a wall
'E' is an open space representing an entrance. All entrances will occur on the outer perimeter (as defined by the w and h values) of the maze and no two entrances will be adjacent.

All mazes will be completely enclosed by a combination of 'X' and 'E' characters.
Output

For each maze, print a single line of output of the form

The goal would be found from ? out of ? entrances.

replacing the first '?' by the number of entrances from which the right-hand-rule allows one to find the goal and the second '?' by the total number of entrances.
Sample Input

31 15
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X X
X X
X X
X XXXX XXXXX X
X X X X
X X G X X
X X X X
X X X X
X XXXXXXXXXX X
X X
X X
X XXXXXXXXXXXXX
X X
XXXXXXEXXXXXXXXXXXXXXXEXXXXXXXX
0 0
Sample Output

The goal would be found from 1 out of 2 entrances.

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真