Board covering problems

    

     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.
     (残缺棋盘是一个有2k×2k (k≥1)个方格的棋盘,其中恰有一个方格残缺。图4-7给出k=1时各种可能的残缺棋盘,其中残缺的方格用阴影表示。)
      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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值