合併排序

 
#include <iostream>
#include <cmath>
using namespace std;

const int MAX_SIZE = 1024;

int count = 0;

int ChessTable[MAX_SIZE][MAX_SIZE]={0};
int cout_L[4] = {0};

int Chess(const int &input_x,const int &input_y, const int top_left_x, int top_left_y, int size)
{
 if(size == 1)
   if( ChessTable[top_left_x][top_left_y] == 1)
   {
  return 0;
   }

   size = size/2;
    
 if(input_x < top_left_x + size && input_y < top_left_y + size)
 {
  Chess(input_x,input_y,top_left_x,top_left_y,size);
  cout_L[0]++;
 }
 else
 {
  ChessTable[top_left_x+size-1][top_left_y+size-1] = 1;
  Chess(top_left_x+size-1,top_left_y+size-1,top_left_x,top_left_y,size);
 }

 if(input_x >= top_left_x + size && input_y < top_left_y + size)
 {
  Chess(input_x,input_y,top_left_x+size,top_left_y,size);
  cout_L[1]++;
 }
 else
 {
  ChessTable[top_left_x+size][top_left_y+size-1] = 1;
  Chess(top_left_x+size,top_left_y+size-1,top_left_x+size,top_left_y,size);
 }

 if(input_x < top_left_x + size && input_y >= top_left_y + size)
 {
  Chess(input_x,input_y,top_left_x,top_left_y+size,size);
  cout_L[2]++;
 }
 else
 {
  ChessTable[top_left_x+size-1][top_left_y+size] = 1;
  Chess(top_left_x+size-1,top_left_y+size,top_left_x,top_left_y+size,size);
 }

 if(input_x >= top_left_x + size && input_y >= top_left_y + size)
 {
  Chess(input_x,input_y,top_left_x+size,top_left_y+size,size);
  cout_L[3]++;
 }
 else
 {
  ChessTable[top_left_x+size][top_left_y+size] = 1;
  Chess(top_left_x+size,top_left_y+size,top_left_x+size,top_left_y+size,size);
 } 
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章