• 《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 }
  • 相关阅读:
    基础--补习汇编笔记--1
    SpProcPool阅读笔记--1
    一般树--common tree
    code-reading-notes--xml 解析
    code-reading-notes--libyang-1
    linux--rbtree 解惑 insert
    记录一次手动杀毒过程
    B-Tree概念
    db2 -- 存储过程01
    sql server 带输入输出参数的分页存储过程(效率最高)
  • 原文地址:https://www.cnblogs.com/zhuli19901106/p/3610501.html
Copyright © 2020-2023  润新知