Board algorithms divide and conquer

Source: Internet
Author: User
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;

Namespace chessboard
{
Class Program
{
Public static int [,] Board = new int [8, 8];
Public static int tail = 0;
Static void main (string [] ARGs)
{
Chessboard (0, 0, 4, 7, 8 );
For (INT I = 0; I <8; I ++)
{
For (Int J = 0; j <8; j ++)
{
Console. Write ("{0, 5}", Board [I, j]);
}
Console. Write ("\ n ");
}
Console. Read ();
}

Public static void chessBoard (int tr, int tc, int dr, int dc, int size)
{
If (size = 1) return;
Int s = size/2;
Int t = tail ++;
// The Special square is in the upper left corner.
If (Dr <tr + S & DC <TC + S)
{
Chessboard (TR, TC, Dr, DC, S );
}
Else
{
// The Special square is not in the upper left corner.
Board [tr + s-1, tc + s-1] = t;
ChessBoard (tr, tc, tr + s-1, tc + s-1, s );
}

// The Special square is in the upper right corner.
If (dr <tr + s & dc> = tc + s)
{
Chessboard (TR, TC + S, Dr, DC, S );
}
Else
{
// The Special square is not in the upper right corner.
Board [tr + s-1, TC + S] = T;
Chessboard (TR, TC + S, tr + s-1, TC + S, S );
}

// The Special square is in the lower left corner.
If (dr> = tr + s & dc <tc + s)
{
ChessBoard (tr + s, tc, dr, dc, s );
}
Else
{
// The Special square is not in the lower left corner.
Board [tr + s, tc + s-1] = t;
ChessBoard (tr + s, tc, tr + s, tc + s-1, s );
}

// The Special square is in the lower right corner.
If (dr> = tr + s & dc> = tc + s)
{
ChessBoard (tr + s, tc + s, dr, dc, s );
}
Else
{
// The Special square is not in the lower right corner.
Board [tr + s, tc + s] = t;
ChessBoard (tr + s, tc + s, tr + s, tc + s, s );
}

}
}
}

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.