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
分治算法--循环赛日程表
最新推荐文章于 2021-03-27 20:09:30 发布