分治算法--循环赛日程表

 
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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值