求算法, 9 张正方形卡片,每个卡片上有4个 一半的昆虫,一共有4种昆虫,每个昆虫有头有尾, 要求 把这9个正方型卡片,拼成3*3 的正方形,并且每个虫子都连好头和尾。大家有何Idea?暂时 我设计的数据结构,一个二维数组, 包括, 卡片 旋转信息, 什么样的虫子, 上半身还是下半身,,等等大侠们请赐教!谢谢

解决方案 »

  1.   

    穷举法搞定了, 数据结构:
      TBugSide = (
        ////////////////////////////////////////////////////////////////////////////
        // Enumeration defining the heads and tails of the insects in the puzzle.
        // Each insect has a different colour.
        tbsBlackHead,                                 //this the head of a black bug
        tbsBlackTail,                                 //this the tail of a black bug
        tbsBlueHead,                                  //this the head of a blue bug
        tbsBlueTail,                                  //this the tail of a blue bug
        tbsGreenHead,                                 //this the head of a green bug
        tbsGreenTail,                                 //this the tail of a green bug
        tbsRedHead,                                   //this the head of a red bug
        tbsRedTail                                    //this the tail of a red bug
        );  TPieceSide = (
        ////////////////////////////////////////////////////////////////////////////
        // Enumeration defining the the 4 sides of each piece which are north, east,
        // south, west.
        tpsNorth,                                     //the North side
        tpsEast,                                      //the east side
        tpsSouth,                                     //the south side
        tpsWest                                       //the west side
        );9层 loop