《算法设计与分析》王晓东编著
源代码在线查看: table.java
import java.util.Scanner;
public class Table {
public static int[][] table;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.print("Please input the number of players n(n=2^k):");
int n = in.nextInt();
table = new int[n][n];
for(int i=0;i table[i][0] = i+1;
}
table(0,0,n);
System.out.print("Match table:\n");
for(int i=0;i for(int j=0;j System.out.print(table[i][j]+"\t");
}
System.out.println();
}
}
public static void table(int x,int y,int size){
if (size==1) return;
int s = size/2;
table(x,y,s);
table(x+s,y,s);
copyArea(x+s,y,x,y+s,s);
copyArea(x,y,x+s,y+s,s);
}
public static void copyArea(int sx,int sy,int dx,int dy,int s){
for(int i=0;i for(int j=0;j table[dx+i][dy+j] = table[sx+i][sy+j];
}
}
}