棋盤覆蓋問題

2021-07-29 06:46:38 字數 1035 閱讀 5136

#include using namespace std;

const int maxn = 2000;

int graph[maxn][maxn];

int ans;

int px, py;//棋盤大小以及黑塊的位置

void dfs(int x, int y, int len)

ans++;//每次遞迴都會有三個角模擬成黑色湊出乙個l,所以直接把結果+1

len /= 2;

//把棋盤劃分為4個子塊,分別遞迴求解

//左上

if (x <= px && px <= x + len - 1 && y <= py && py <= y + len - 1)

else

//左下

if (x + len <= px && px <= x + len*2 - 1 && y <= py && py <= y + len - 1)

else

//右上

if (x <= px && px <= x + len - 1 && y + len <= py && py <= y + len*2 - 1)

else

//右下

if (x + len <= px && px <= x + len*2 - 1 && y + len <= py && py <= y + len*2 - 1)

else

}int main()

cout << "2^" << len << "*2^" << len << "的棋盤已經建立" << endl;

cout << "請輸入特殊位置的座標(原點為1,1):";

cin >> px >> py;

if( px > (1<(1

memset(graph, 0, sizeof(graph));

graph[px][py] = 1;

dfs(1, 1, 1

return 0;

}

棋盤覆蓋問題

source code include include include using namespace std const int n 1024 int board n n count void cover int sx,int sy,int cx,int cy,int size,int cx1,i...

棋盤覆蓋問題

問題 在乙個2k 2k k 0 個方格組成的棋盤中,恰有乙個方格與其他方格不同,稱該方格為特殊方格。顯然,特殊方格在棋盤中可能出現的位置有4k種,因而有4k種不同的棋盤,圖4.10 a 所示是k 2時16種棋盤中的乙個。棋盤覆蓋問題 chess cover problem 要求用圖4.10 b 所示...

棋盤覆蓋問題

棋盤覆蓋問題 time limit 1000ms,special time limit 2500ms,memory limit 32768kb total submit users 103,accepted users 40 problem 10432 no special judgement pr...