using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChessBoard
{
    
class Program
    {
        
public static int[,] Board = new int[88];
        
public static int tail = 0;
        
static void Main(string[] args)
        {
            chessBoard(
00478);
            
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 == 1return;
            
int s = size / 2;
            
int t = tail++;
            
//特殊方块在左上角
            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);
            }

        }
    }
}

相关文章:

  • 2021-09-08
  • 2022-12-23
  • 2021-09-19
  • 2021-07-03
  • 2021-09-07
  • 2021-06-30
  • 2022-01-22
猜你喜欢
  • 2021-11-02
  • 2021-04-05
  • 2021-11-05
  • 2021-11-29
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案