《算法设计与分析》王晓东编著

源代码在线查看: table.java

软件大小: 13 K
上传用户: zergwyk
关键词: 算法 设计与分析
下载地址: 免注册下载 普通下载 VIP

相关代码

				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];
						}
					}
				
				}
							

相关资源