分治演算法–迴圈賽議程表

來源:互聯網
上載者:User

 

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.