zoukankan      html  css  js  c++  java
  • 递归与分治

    棋盘覆盖

    2^k的棋盘格子,有一个缺陷,用L形状的的拼图把棋盘覆盖。

    每次涂抹的时候先按照缺陷的四周涂抹……23333

    参考

    int dir[4][2] = {{0,0},{0,1},{1,0},{1,1}};  ///棋盘L形状对应的分别缺少那个格子
    int graph[10000][10000];
    void set_piece(int r,int c,int x){  ///r,c代表所要涂抹的位置,x表示涂抹的哪种类型,其他的表示不涂抹
        for(int i = 0;i < 4;i++){
            if(i == x)
                continue;
            graph[r+dir[i][0]][c+dir[i][1]] = x+1;
        }
    }
    void chessBoard(int sx,int sy,int x,int y,int len){
        if(len == 1)
            return;
        int s = len / 2;
        int dx = x >= sx + s; ///判断缺陷位置
        int dy = y >= sy + s;
        for(int i = 0;i < 4;i++){
            if(dir[i][0] != dx || dir[i][1] != dy)
                continue;
            set_piece(sx+s-1,sy+s-1,i);
            for(int j = 0;j < 4;j++){
                int ssx = sx + dir[j][0] * s;
                int ssy = sy + dir[j][1] * s;
                if(i == j){
                    chessBoard(ssx,ssy,x,y,s);
                }
                else{
                    int ex = sx + s - 1 + dir[j][0];
                    int ey = sy + s - 1 + dir[j][1];
                    chessBoard(ssx,ssy,ex,ey,s);
                }
            }
        }
    }
  • 相关阅读:
    图的深度遍历
    判断森林中有多少棵树
    基于邻接矩阵的广度优先搜索
    第三届程序设计知识竞赛网络赛
    大数相乘
    a+b=x,ab=y
    poj3278
    不敢死队
    单链表中重复元素删除
    poj2506
  • 原文地址:https://www.cnblogs.com/hanbinggan/p/4298976.html
Copyright © 2011-2022 走看看