#include<cstdio>
#include<cmath>
#include<stdio.h>
#include <iostream>
using namespace std;
#define max 1024
int cb[max][max];//最大棋盘
int id = 0;//覆盖标志位
int chess(int tr, int tc, int dr, int dc, int size) {
if (size == 1) return 0;
int s = size / 2;
int t = id++;
if (dr < tr + s && dc < tc + s) {
chess(tr, tc, dr, dc, s);
}
else
{
cb[tr + s - 1][tc + s - 1] = t;//构造完毕
chess(tr, tc, tr + s - 1, tc + s - 1, s);
}
if (dr >= tr + s && dc < tc + s) {
chess(tr, tc, dr, dc, s);
}
else {
cb[tr + s][tc + s - 1] = t;
chess(tr + s, tc, tr + s, tc + s - 1, s);
}
if (dc >= tc + s && dr < tr + s) {
chess(tr, tc + s, dr, dc, s);
}
else {
cb[tr + s - 1][tc + s] = t;
chess(tr, tc + s, tr + s - 1, tc + s, s);
}
if (dc >= tc + s && dr >= tr + s) {
chess(tr + s, tc + s, dr, dc, s);
}
else {
cb[tr + s][tc + s] = t;
chess(tr + s, tc + s, tr + s, tc + s, s);
}
return 0;
}
int main() {
int size = 0;
int i, j;
cout << "输入棋盘大小" << endl;
cin >> size;
cout << "输入不可覆盖点位置:" << endl;
cin >> i >> j;
cb[i][j] = -1;
chess(0, 0, i, j, size);
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
cout << cb[i][j]<<" ";
cout << endl;
}
cout << "不可覆盖点值为-1";
return 0;
}
2020-9-26,棋盘覆盖
于 2020-09-26 16:40:01 首次发布