package java2; import java.util.Scanner; public class Java2 { static int max_size=16; static int[][] board=new int[max_size][max_size]; static int tile=0; public static int chessBoard(int tr,int tc,int dr,int dc,int size){ if(size==1) return 0; int t=tile++; int s=size/2; if(dr<tr+s&&dc<tc+s){ chessBoard(tr,tc,dr,dc,s); }else{ board[tr+s-1][tc+s-1]=t; chessBoard(tr,tc,tr+s-1,tc+s-1,s); } if(dr<tr+s&&dc>=tc+s){ chessBoard(tr,tc+s,dr,dc,s); }else{ board[tr+s-1][tc+s]=t; chessBoard(tr,tc+s,tr+s-1,tc+s,s); } if(dr>=tr+s&&dc<tc+s){ chessBoard(tr+s,tc,dr,dc,s); }else{ board[tr+s][tc+s-1]=t; chessBoard(tr+s,tc,tr+s,tc+s-1,s); } if(dr>=tr+s&&dc>=tc+s){ chessBoard(tr+s,tc+s,dr,dc,s); }else{ board[tr+s][tc+s]=t; chessBoard(tr+s,tc+s,tr+s,tc+s,s); } return 0; } public static void main(String arg[]){ Scanner input=new Scanner(System.in); System.out.println("特殊方格在棋盘数组Board中的行号"); int dr=input.nextInt();//特殊方格在棋盘数组Board中的行号 System.out.println("特殊方格在棋盘数组Board中的列号"); int dc=input.nextInt();//特殊方格在棋盘数组Board中的列号 System.out.println("棋盘边长"); int size=input.nextInt();//棋盘边长 System.out.print(" "); chessBoard(0,0,dr,dc,size); for(int i=0;i<size;i++){ for(int j=0;j<size;j++) System.out.print(board[i][j]+" "); System.out.print(" "); } } }