循环赛日程表(非递归)

#include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

/*
*循环赛日程表(非递归)
*/

void Copy(int **map,int sr,int sl,int dr,int dl,int k)
{
	for (int i = 0; i < k; i++)
	{
		for (int j = 0; j < k; j++)
		{
			map[dr+i][dl+j] = map[sr+i][sl+j];
		}
	}
}

void Table(int **map,int k)
{
	for (int i = 2; i <= k; i<<=1)
	{
		for (int j = 0; j < k; j+=i)
		{
			//从左上角复制到右下角
			Copy(map,0,j,0+i/2,j+i/2,i/2);
			//从右上角复制到左下角
			Copy(map,0,j+i/2,0+i/2,j,i/2);
		}
	}
}

int main()
{
	int k;
	//输入运动员的人数
	cin>>k;
	int ** p =new int*[k];
	//赛程表初始化
	for (int i = 0; i < k; i++)
	{
		p[i] = new int[k];
		p[0][i] = i+1;
		p[i][0] = i+1;
	}
	//执行函数
	Table(p,k);
	//输出结果
	cout<<"循环赛日程表(非递归法):"<<endl;
	for (int i = 0; i < k; i++)
	{
		copy(p[i],p[i]+k,ostream_iterator<int>(cout," "));
		cout<<endl;
	}
	return 0;
}

posted @ 2015-12-26 11:13  blfshiye  阅读(541)  评论(0编辑  收藏  举报