package algorithm;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
public class Checkborder {
static int tile = 0;
static int[][] Matrix = new int[100][100];
public static void main(String[] args) throws IOException {
int k;
int[] postion = new int[2];
System.out.println("请输入棋盘大小:");
Scanner sc = new Scanner(System.in);
k = sc.nextInt();
System.out.println("请输入特殊格坐标:");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
postion[0] = Integer.parseInt(in.readLine());
postion[1] = Integer.parseInt(in.readLine());
System.out.println(Arrays.toString(postion));
chessBorder(0,0,postion[0],postion[1],k);
for(int i=0;i<k;i++){
for (int j=0;j<k;j++){
System.out.print(Matrix[i][j]);
}
System.out.println();
}
}
public static void chessBorder(int tr,int tc,int dr,int dc,int size){
if(size==1) return;
else {
int s = size/2;
int t = ++tile;
if(dr<tr+s&&dc<tc+s){
chessBorder(tr,tc,dr,dc,s);
}else{
Matrix[tr+s-1][tc+s-1] = t;
chessBorder(tr, tc, tr+s-1, tc+s-1, s);
}
if(dr<tr+s&&dc>=tc+s){
chessBorder(tr,tc+s,dr,dc,s);
}else{
Matrix[tr+s-1][tc+s] = t;
chessBorder(tr, tc+s, tr+s-1, tc+s, s);
}
if(dr>=tr+s&&dc<tc+s){
chessBorder(tr+s,tc,dr,dc,s);
}else{
Matrix[tr+s][tc+s-1] = t;
chessBorder(tr+s, tc, tr+s, tc+s-1, s);
}
if(dr>=tr+s&&dc>=tc+s){
chessBorder(tr+s,tc+s,dr,dc,s);
}else{
Matrix[tr+s][tc+s] = t;
chessBorder(tr+s, tc+s, tr+s, tc+s, s);
}
}
}
}