-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path棋盘覆盖.java
65 lines (58 loc) · 1.7 KB
/
棋盘覆盖.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.company;
import java.util.Scanner;
public class Main {
final static int N = 110;
public static int cnt;
public static int [][] mp;
public static void chessBoard(int x, int y, int sz, int dr, int dc){
if(sz == 1)
return;
sz/=2;
int t = cnt++;
if(dr < x+sz && dc < y+sz){
chessBoard(x, y, sz, dr, dc);
} else {
mp[x + sz - 1][y + sz - 1] = t;
chessBoard(x, y, sz, x + sz - 1, y + sz - 1);
}
if(dr < x+sz && dc >= y+sz){
chessBoard(x, y+sz, sz, dr, dc);
} else {
mp[x+sz-1][y+sz] = t;
chessBoard(x, y+sz, sz, x+sz-1, y+sz);
}
if(dr >= x+sz && dc < y+sz){
chessBoard(x+sz, y, sz, dr, dc);
} else {
mp[x+sz][y+sz-1] = t;
chessBoard(x+sz, y, sz, x+sz, y+sz-1);
}
if(dr >= x+sz && dc >= y+sz){
chessBoard(x+sz, y+sz, sz, dr, dc);
} else {
mp[x + sz][y + sz] = t;
chessBoard(x + sz, y + sz, sz, x + sz, y + sz);
}
}
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n,dr,dc;
n = cin.nextInt();
dr = cin.nextInt();
dc = cin.nextInt();
mp = new int [N][N];
int [] fac = new int [N];
fac[0] = 1;
for(int i=1;i<=6;i++){
fac[i] =fac[i-1] * 2;
}
mp[dr][dc] = cnt++;
chessBoard(0, 0, fac[n], dr, dc);
for(int i=0;i<fac[n];i++){
for(int j=0;j<fac[n];j++){
System.out.print(mp[i][j] + " ");
}
System.out.println();
}
}
}