棋盘覆盖问题 - 分治法

程序如下:

public class Chess
{
	static int tile=1;                   //L型骨牌的编号(递增)
	static int board[][] = new int[100][100];  //棋盘
	public static void main(String[] args)
	{
		int size =8;
		chessBoard ( 0,0,3,3,size);
		for ( int i=0; i=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=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 );
		}
	
	}
}
结果如下:
   3   3   4   4   8   8   9   9
   3   2   2   4   8   7   7   9
   5   2   6   6  10  10   7  11
   5   5   6   0   1  10  11  11
  13  13  14   1   1  18  19  19
  13  12  14  14  18  18  17  19
  15  12  12  16  20  17  17  21
  15  15  16  16  20  20  21  21




你可能感兴趣的:(java语言,数据结构和算法)