You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
# define N 50
//声明日程表安排函数
void GameTable ( int k , int array [ N ] [ N ] ) ;
//输出二维数组
void Print ( int k , int array [ N ] [ N ] ) ;
int main ( ) {
int k ;
int array [ N ] [ N ] ;
cout < < " **************************************** " < < endl ;
cout < < " ** 循环赛日程表 ** " < < endl ;
cout < < " **************************************** " < < endl ;
cout < < " 设参赛选手的人数为n( n=2^k) , 请输入k 的值: " < < endl ;
cin > > k ;
if ( k ! = 0 ) {
GameTable ( k , array ) ;
Print ( k , array ) ;
} else
cout < < " 您输入的数据有误,请重新输入! " < < endl ;
return 0 ;
}
//数组下标从1开始
void GameTable ( int k , int array [ N ] [ N ] ) {
int i , j , s , t ;
//个数
int n = 1 < < k ;
//求总人数
for ( i = 1 ; i < = n ; i + + )
array [ 1 ] [ i ] = i ; //第一行排1-8
int m = 1 ; //用来控制每一次填表时i行j列的起始填充位置
//s指对称赋值的总循环次数, 即分成几大步进行制作日程表
for ( s = 1 ; s < = k ; s + + ) {
n = n / 2 ;
for ( t = 1 ; t < = n ; t + + ) //t指明内部对称赋值的循环次数
for ( i = m + 1 ; i < = 2 * m ; i + + )
for ( j = m + 1 ; j < = 2 * m ; j + + ) {
array [ i ] [ j + ( t - 1 ) * m * 2 ] = array [ i - m ] [ j + ( t - 1 ) * m * 2 - m ] ; //右上角等于左上角的值
array [ i ] [ j + ( t - 1 ) * m * 2 - m ] = array [ i - m ] [ j + ( t - 1 ) * m * 2 ] ; //左下角等于右上角的值
}
m * = 2 ;
}
}
//输出二维数组
void Print ( int k , int array [ N ] [ N ] ) {
int i , j ;
int num = pow ( 2 , k ) ;
cout < < num < < " 人的循环赛日程表如下 " < < endl ;
//输出二维数组
for ( i = 1 ; i < = num ; i + + ) {
for ( j = 1 ; j < = num ; j + + ) {
cout < < array [ i ] [ j ] < < " \t " ;
}
cout < < endl ;
}
cout . flush ( ) ;
}