package divideConquer;public class ScheduleRoundRobin {/* there will n team competition,you must design * a schedule to fill the bill * 1.every team must play with other n-1 team * 2.a team only take part in a competition * 3.if n is odd,the whole day of competion is n-1; * otherwise,the day is n * * */// 這個只是應用於 2 的k 次方個人蔘加比賽,因為在分治過程中// 不允許出現奇數public static void divide(int data[][],int n){if(n==1){data[1][1] = 1;return ;}divide(data,n/2);conquer(data, n);}public static void conquer(int data[][],int n){int m = n/2;for(int i=1;i<=m;i++){for(int j=1;j<=m;j++){data[i][j+m] = data[i][j]+m;data[i+m][j] = data[i][j+m];data[i+m][j+m] = data[i][j];}}}public static void main(String args[]){int n = 14;int data[][] = new int[n+1][n+1];divide(data,n+1);for(int i=1;i<n+1;i++){for(int j=1;j<n+1;j++) System.out.print(data[i][j]+" ");System.out.println();}}}
轉載:http://blog.sina.com.cn/s/blog_5a16b28c0100efjh.html