Incomplete board is a 2 k x 2 k (k: 1) a square board, which just have a box missing. Figure 4-7 give k = 1 all possible incomplete board, including incomplete squares with shadow said.
Song ti board so we called "three case board", incomplete problem is to use this board four three case board over a large incomplete board. On the cover of requirements:
1) two three case board can't overlap
2) three case board can't cover incomplete box, but must cover all other squares
In this restricted condition, need three case board for a total of (2 k x 2 k-1) / 3.
(像这样的棋盘我们称作“三格板”,残缺棋盘问题就是要用这四种三格板覆盖更大的残缺棋盘。在此覆盖中要求:
1)两个三格板不能重叠
2)三格板不能覆盖残缺方格,但必须覆盖其他所有的方格
在这种限制条件下,所需要的三格板总数为(2k×2k -1 )/3。
)
program:
//
//棋盘覆盖
#include <stdio.h>
int amount=0;
int Board[100][100];
int Cover(int tr,int tc,int dr,int dc,int size)
{
int s,t;
if(size<2)//结束条件
return 0;
amount=amount+1;
t=amount;
s=size/2;//s右偏,下偏
if((dr<tr+s)&&(dc<tc+s))//左上角
{
Cover(tr,tc,dr,dc,s);//
Board[tr+s-1][tc+s]=t;//
Board[tr+s][tc+s-1]=t;
Board[tr+s][tc+s]=t;
Cover(tr,tc+s,tr+s-1,tc+s,s);//
Cover(tr+s,tc,tr+s,tc+s-1,s);//
Cover(tr+s,tc+s,tr+s,tc+s,s);//
}
else if((dr<tr+s)&&(dc>=tc+s))//右上角
{
Cover(tr,tc+s,dr,dc,s);
Board[tr+s-1][tc+s-1]=t;
Board[tr+s][tc+s-1]=t;
Board[tr+s][tc+s]=t;
Cover(tr,tc,tr+s-1,tc+s-1,s);
Cover(tr+s,tc,tr+s,tc+s-1,s);
Cover(tr+s,tc+s,tr+s,tc+s,s);
}
else if((dr>=tr+s)&&(dc<tc+s))//左下角
{
Cover(tr+s,tc,dr,dc,s);
Board[tr+s-1][tc+s-1]=t;
Board[tr+s-1][tc+s]=t;
Board[tr+s][tc+s]=t;
Cover(tr,tc,tr+s-1,tc+s-1,s);//上边
Cover(tr,tc+s,tr+s-1,tc+s,s);//对角
Cover(tr+s,tc+s,tr+s,tc+s,s);//右边
}
else if((dr>=tr+s)&&(dc>=tc+s))//右下角
{
Cover(tr+s,tc+s,dr,dc,s);//
Board[tr+s-1][tc+s-1]=t;
Board[tr+s-1][tc+s]=t;
Board[tr+s][tc+s-1]=t;
Cover(tr,tc,tr+s-1,tc+s-1,s);//
Cover(tr,tc+s,tr+s-1,tc+s,s);//
Cover(tr+s,tc,tr+s,tc+s-1,s);//
}
return 0;
}
OutputBoard(int size)
{
int i,j;
for(i=0;i<size;++i)
{
for(j=0;j<size;++j)
printf("%d--",Board[i][j]);
printf("\n==================\n");
}
}
int main()
{
int size=1;
int x,y,i,k;
printf("k:");
scanf("%d",&k);
for(i=1;i<=k;++i)
size=size*2;
printf("input incomplete pane:");
scanf("%d %d",&x,&y);
Cover(0,0,x,y,size);
OutputBoard(size);
return 0;
}
本文介绍了如何通过一种特定的算法,利用四种三案板覆盖一个2k×2k(k≥1)的棋盘,其中恰好有一个方格缺失。在覆盖过程中遵循了特定的规则,例如三个案板不能重叠,且必须覆盖除缺失方格外的所有方格。文章详细阐述了算法实现过程,并提供了相应的代码。

1016

被折叠的 条评论
为什么被折叠?



