• 《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 }
  • 相关阅读:
    第七周作业
    第六周作业
    CSS
    12 week work
    7 week work
    6 week work 3
    6 week work 2
    6 week work 1
    常用的网络服务小总结
    网络基础设置
  • 原文地址:https://www.cnblogs.com/zhuli19901106/p/3610501.html
Copyright © 2020-2023  润新知