Division and Recursion-ContestTable


#include<iostream>
using namespace std;

int copyTimes(int playerNumber)
{
 int i =0;

 while(playerNumber != 1){
  playerNumber = playerNumber/2;
  i++;
 }
 return i;
}


void countContestArrangementTble(int array[][9], int playerNumber){
 for (int i = 1; i <= playerNumber; i++) array[1][i] = i;
    int expandTimes = copyTimes(playerNumber);
    int stepLength = 1;
 int stepTimesOfOneExpand =0 ;
  for(int i=1; i<=expandTimes;i++){
   
       stepTimesOfOneExpand = playerNumber/2;

   for(int step = 1; step <= stepTimesOfOneExpand; step++)
   {
    for(int row = stepLength+1; row <= 2*stepLength; row++)
    {
     for(int col = stepLength+1; col <= 2*stepLength; col++)
     {
      /*left up----right bottom*/
      array[row][col+(step-1)*stepLength*2]
      =array[row-stepLength][col - stepLength + (step-1)*stepLength*2];
      array[row][col+(step-1)*stepLength*2-stepLength]
      = array[row-stepLength][col + (step-1)*stepLength*2];
     }
    }
   }
      stepLength *=2;

  }
}
int main(){
 cout<<copyTimes(8)<<endl;
 int array[9][9]={0};
 countContestArrangementTble(array,8);

 for(int i =1; i<=8;i++)
 {
  for(int j =1; j<=8;j++)
  {
   cout<<array[i][j];
  }
  cout<<endl;
 }
}

posted @ 2016-03-19 16:46  zhaodonglin  Views(102)  Comments(0)    收藏  举报