zoukankan      html  css  js  c++  java
  • [练习]solveMaze

    Practice:

      Although Euclid’s algorithm and the problem of finding perfect numbers from the preceding exercise are both drawn from the domain of mathematics, the Greeks were fascinated with algorithms of other kinds as well.  In Greek mythology, for example, Theseus of Athens escapes from the Minotaur’s labyrinth by taking in a ball of string, unwinding it as he goes along, and then following the path of string back to the exit.  Theseus’s strategy represents an algorithm for escaping from a maze, but it is not the only algorithm he could have used to solve this problem.  For example, if a maze has no internal loops, you can always escape by keeping your right hand against a wall at all times.  This algorithm is called the right-hand rule.

    For example, imagine that Theseus is in the maze shown below at the position marked by the Greek letter theta (Θ):

      To get out, Theseus walks along the path shown by the dotted line in the next diagram, which he can do without taking his right hand off the wall.

      

      Suppose you have been asked to write a program for a robot named Theseus to escape from a maze.  You have access to a library that contains these methods:

    void moveForward();     /* Move forward to the next square   */

    void turnRight();       /* Turn right without moving         */

    void turnLeft();        /* Turn left without moving          */

    boolean isFacingWall(); /* True if Theseus is facing a wall  */

    boolean isOutside();    /* True if Theseus has left the maze */

    Use these methods to write an algorithmic method solveMaze that implements the right-hand rule.

    不断的总结,才能不断的提高;不断的思考,才能不断的进步!
  • 相关阅读:
    CentOS下Apache开启Rewrite功能
    CentOS下Apache配置多域名或者多端口映射
    CentOS配置SVN服务器
    Windows下Apache配置域名
    PHP 返回13位时间戳
    主成分分析(PCA)特征选择算法详解
    均值、方差、标准差及协方差、协方差矩阵详解
    Jackson序列化日期类型的属性
    监控JVM内存使用情况,剩余空间小于2M时报警
    java 7中新增的CPU和负载的监控
  • 原文地址:https://www.cnblogs.com/nzyjlr/p/2009684.html
Copyright © 2011-2022 走看看