竞赛选手问题的解答算法

时间:2023-01-08 18:26:24

// Detach.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#define MAXN 64
int array[MAXN+1][MAXN];
int main(int argc, char* argv[])
{
 int twon1,twon2,i,j,m,k;
 printf("指定n(n=2的k次幂)位选手/n");
 scanf("%d",&k);
 array[1][1] = 2;
 array[2][1] = 1;
 m = 1;
 twon2 = 1;
 while(m {
  m++;
  twon2 += twon2;
  twon1 = 2*twon2;
  for(i=twon2+1;i<=twon1;i++)
   for(j=1;j<=twon2-1;j++)
    array[i][j] = array[i-twon2][j]+twon2;
  array[1][twon2] = twon2+1;
  for(i=2;i<=twon2;i++)
   array[i][twon2] = array[i-1][twon2]+1;
  for(j=twon2+1;j  {
   for(i=1;j    array[i][j] = array[i+1][j-1];
   array[twon2][j] = array[1][j-1];
  }
  for(j=twon2;j   for(i=1;j<=twon2;i++)
    array[array[i][j]][j] = i;
  for(i=1;i<=twon1;i++)
  {
   for(j=1;j    printf("%4d",array[i][j]);
   printf("/n");
  }
  printf("/n");
 }
 printf("/n/n应用程序正在运行....../n");
 return 0;
}

 



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=935652