Recursive Sub-governance solves the Board coverage Problem

Source: Internet
Author: User
Package algorithm; // recursive grouping solves the Board coverage problem. Public class chessboard {// tr the row number in the upper left corner of the board. // column number in the upper left corner of the TC board. // size = 2 ^ K the board type is 2 ^ K * 2 ^ K // row number of the Dr special square // column number of the DC special square Private Static int tile = 0; // L-type bone number public static int [] [] Board = new int [100] [100]; public static void chessboard (int tr, int TC, int DR, int DC, int size) {If (size = 1) return; size/= 2; int T = ++ tile; // If (Dr <tr + size & DC <TC + size) {chessboard (TR, TC, Dr, DC, size );} else {board [tr + size-1] [TC + size-1] = T; chessboard (TR, TC, tr + size-1, TC + size-1, size) ;}// if (Dr <tr + size & DC> = TC + size) {chessboard (TR, TC + size, Dr, DC, size);} else {board [tr + size-1] [TC + size] = T; chessboard (TR, TC + size, tr + size-1, TC + size, size) ;}// if (Dr> = tr + size & DC <TC + size) {chessboard (tr + size, TC, Dr, DC, size);} else {board [tr + size] [TC + size-1] = T; chessboard (tr + size, TC, tr + size, TC + size-1, size) ;}// if (Dr> = tr + size & DC> = TC + size) {chessboard (tr + size, TC + size, Dr, DC, size) ;}else {board [tr + size] [TC + size] = T; chessboard (tr + size, TC + size, tr + size, TC + size, size) ;}} public static void main (string [] ARGs) {// todo auto-generated method stubint size = 8; chessboard (0, 0, 3, 3, size ); for (INT I = 0; I <size; I ++) {for (Int J = 0; j <size; j ++) {string S = string. format ("% 3d", Board [I] [J]); system. out. print (s);} system. out. println ();}}}

Recursive Sub-governance solves the Board coverage Problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.