简单acm题:棋盘覆盖

Description

 

在一个2k x 2k 个方格组成的棋盘中,恰有一个方格与其他方格不同,称该方格为一特殊方格,且称该棋盘为一特殊棋盘。在棋盘覆盖问题中,要用图示的4种不同形态的L型骨牌覆盖给定的特殊棋盘上除特殊方格以外的所有方格,且任何2个L型骨牌不得重叠覆盖。 

 

Input

 

k,dr,dc。k定义如前,dr,dc分别表示特殊方格所在的行号和列号 1= < k < =6

 

Output

 

按照左上,右上,左下,右下的顺序用分治法求解。特殊方格标0,其他位置按上述顺序依次标记。

 

Sample Input

2 1 1

Sample Output

2 2 3 3 
2 0 1 3 
4 1 1 5 
4 4 5 5 

 

//棋盘覆盖只需要不断的把棋盘分小然后用上述的L骨牌来把他变为特殊方格
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;
#define ll long long
const int N = 1e6+5;
int a[100][100];
int cnt=1;

void f(int tr,int tc,int dr,int dc,int flag)//递归程序
{
    if(flag == 1)
        return ;
    int t = cnt++; //L型骨牌号
    int s = flag/2;  //分割棋盘
    //覆盖左上
    if(dr =tc+s)
        f(tr,tc+s,dr,dc,s);
    else
    {
        //用t号L方格来覆盖左下角
        a[tr+s-1][tc+s]=t;
        f(tr,tc+s,tr+s-1,tc+s,s);
    }
    //左下角
    if(dr >=tr+s&& dc=tr+s&& dc>=tc+s)
        f(tr+s,tc+s,dr,dc,s);
    else
    {    //用t号L方格来覆盖左上角
        a[tr+s][tc+s]=t;
        f(tr+s,tc+s,tr+s,tc+s,s);
    }


}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(a,0,sizeof(a));
    int k,dr,dc;
    cin>>k>>dr>>dc;
    int tmp=pow(2,k);
    f(0,0,dr,dc,tmp);
    for(int i = 0 ;i

 

你可能感兴趣的:(acm算法)