|
code:
#include
#include
#include
#define MAXN 256
using namespace std;
void Round_play(int number, int (&cal)[MAXN+1][MAXN]);
int main(int argv, char **argc)
{
int number;
int i, j;
int cal[MAXN+1][MAXN] = {0};
cout<<"Input the number of player(2^n):";
cin>>number;
Round_play(number, cal);
int length = (int)pow(2, number);
cout<<" ";
for(int k = 1; k <= length; k++ )
{
cout<<K<<"天";
}
cout<<ENDL;
for( i = 1; i <= length; i++)
{
cout<<"第"<<I<<"个选手的对手:";
for (j = 1; j < length; j++)
{
cout<<CAL[j]<<" ";
if(j%(length-1) == 0)
cout<<ENDL;
}
}
system("pause") ;
return 0;
}
void Round_play(int number, int(&cal)[MAXN+1][MAXN])
{
int col, row, m, playernumber, tag1, tag2;
playernumber = number;
cal[1][1] = 2;
cal[2][1] = 1;//预先置第1和第2位选手比赛
m = 1;
tag1 = 1;
for (; m < playernumber; )
{
m++;
tag1 += tag1;
tag2 = 2*tag1; //安排2^m位选手比赛
//首先填充日程表的左下方
for (col = tag1 + 1; col <= tag2; col++)
{
for (row = 1; row <= tag1 - 1; row++)
{
cal[col][row] = cal[col - tag1][row] + tag1;//左下方的内容等于左上方的内容对应项tag1
}
}
//然后填充日程表的右上方
//先填日程表的右上方的第1列
cal[1][tag1] = tag1 + 1;
for(col = 2; col <= tag1; col++)
cal[col][tag1] = cal[col-1][tag1] + 1;
//填充日程表的右上方的其他列,填法参照前一列填充当前列,也就是采用循环轮转法
for (row = tag1 + 1; row < tag2; row++)
{
for (col = 1; col < tag1; col++)
{
cal[col][row] = cal[col+1][row-1];
}
cal[tag1][row] = cal[1][row-1];
}
//填充日程表的右下方
for (row = tag1; row < tag2; row++)
{
for (col = 1; col <= tag1; col++)
{
cal[cal[col][row]][row] = col;//这里是查找对应已经填好的项,根据填好的项来填没有填的项
}
}
}
}
PS:col代表行,row代表列,由于写程序的时候搞错了它们的E文意思,so……呵呵,E文不过关呀!之前写好了文档的,可是一不小心把它给删了,后悔呀。 |
|