zoukankan      html  css  js  c++  java
  • 《Cracking the Coding Interview》——第6章:智力题——题目2

    2014-03-19 06:57

    题目:对于8x8的棋盘,如果拿掉对角位置的两个小块儿,能否用1x2的多米诺牌拼成剩下的棋盘?

    解法:不可能。且不说8x8,NxN都是不可能的。如果N是奇数,NxN-2是奇数,自然不可能用偶数的面积拼成。如果N为偶数,根据小学学过的染色问题,将1x2的骨牌染成1黑1白,那么最后拼成的棋盘肯定有31黑31白。问题是,摘掉的两个对角位置的颜色是一样的,所以得出矛盾,也不可能完成。

    代码:

    1 // 6.2 There is an 8x8 chessboard, if we remove the two pieces at diagonal corners, can you cover the rest of the board with 2x1 dominoes?
    2 // Answer:
    3 //    It is impossible. Let's supposed it is feasible, we can color each domino into black and white halves.
    4 //    When the board is completely covered, there'll be 62 1x1 squares, exactly 31 white and 31 black.
    5 //    Actually the two squares removed are in same color, thus you can't turn (30, 32) into (31, 31), however you tile them up.
    6 int main()
    7 {
    8     return 0;
    9 }
  • 相关阅读:
    冲刺阶段 day1
    目标系统流程图 数据流图
    团队作业二
    校外实习报告(十二)
    校外实习报告(十一)
    第二周实习总结
    校外实习报告(十)
    校外实习报告(九)
    校外实习报告(八)
    校外实习报告(七)
  • 原文地址:https://www.cnblogs.com/zhuli19901106/p/3610501.html
Copyright © 2011-2022 走看看