//比赛日程安排
/***
*
- 1 2 3 4
- 2 1 4 3
- 3 4 1 2
- 4 3 2 1 左上角与右下角相同,左下与右上相同
*/
public class test{
public static void main(String args[]){
int num=8;//比赛队伍数量必须是2的幂次数
int result[][]=new int[num][num];
test te=new test();
te.getResult(result, 1, num);
for (int i = 0; i < num; i++) {
for (int j = 0; j < num; j++) {
System.out.print(result[i][j]+" ");
}
System.out.println();
}
}
/***
*
* @param k 开始编号
* @param n 队伍数量
*/
public void getResult(int [][]result,int k,int n){
if(n==2){
//队伍编号
result[k-1][0]=k;
result[k][0]=k+1;
//两队比赛
result[k-1][1]=k+1;
result[k][1]=k;
}else{
getResult(result,k,n/2);
getResult(result, k+n/2, n/2);
//复制左上角到右下角
for (int i = k-1+n/2; i < k-1+n; i++) {
for (int j = n/2; j < n; j++) {
result[i][j]=result[i-n/2][j-n/2];
}
}
//复制左下角到右上角
for (int i = k-1; i < k-1+n/2; i++) {
for (int j = n/2; j < n; j++) {
result[i][j]=result[i+n/2][j-n/2];
}
}
}
}
}