棋牌覆盖问题(分治)
转自 https://www.cnblogs.com/yinbiao/p/8666209.html
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int maxn = 1e3 + 32;
int Map[maxn][maxn];
int total;// L砖块的覆盖编号
// tr,tc为左上角的编号
void ChessMap(int tr,int tc,int dr,int dc,i64 size){
if(size == 1)
return;
int t = total++;
int s = size >> 1;//分割棋盘
if(dr < tr+s && dc < tc + s)
ChessMap(tr,tc,dr,dc,s);//特殊方格
else{
Map[tr+s-1][tc+s-1] = t;
ChessMap(tr,tc,tr+s-1,tc+s-1,s);
}
if(dr < tr+s && dc >= tc+s)//右上角
ChessMap(tr,tc+s,dr,dc,s);
else{
Map[tr+s-1][tc+s] = t;
ChessMap(tr,tc+s,tr+s-1,tc+s,s);
}
if(dr >= tr+s && dc < tc+s){//左下角
ChessMap(tr+s,tc,dr,dc,s);
}else{
Map[tr+s][tc+s-1] = t;
ChessMap(tr+s,tc,tr+s,tc+s-1,s);
}
if(dr >= tr+s && dc >= tc+s){//右下角
ChessMap(tr+s,tc+s,dr,dc,s);
}else{
Map[tr+s][tc+s] = t;
ChessMap(tr+s,tc+s,tr+s,tc+s,s);
}
}
int main(){
int x,y,k;
while(cin >> x >> y >> k){
i64 size = 1 << k;//边长
Map[x][y] = -1;
ChessMap(0, 0, x, y, size);
for(i64 i=0; i<size; i++)
{
for(i64 j = 0; j < size; j++)
cout<< Map[i][j] << "\t";
cout<<"\n";
}
}
}
不怕万人阻挡,只怕自己投降。
posted on 2020-09-06 22:19 chengyulala 阅读(146) 评论(0) 编辑 收藏 举报