⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 安排比赛 用分治法实现 可以重复输入比赛队数
💻 CPP
字号:
#include<stdio.h>
#include<iostream>
#include<iomanip>
using namespace std;

void Table(int N);
void Continue();

void Table(int N)
{
	int a[100][100];
	int q,n=1;
	for(int i=1;i<=N;i++) n*=2;
	q=n;
	for(i=1;i<=n;i++) a[1][i]=i;
	int m=1;
	for(int s=1;s<=N;s++)
	{
		n/=2;
		for(int t=1;t<=n;t++)
			for(i=m+1;i<=2*m;i++)
				for(int j=m+1;j<=2*m;j++){
					a[i][j+(t-1)*m*2]=a[i-m][j+(t-1)*m*2-m];
					a[i][j+(t-1)*m*2-m]=a[i-m][j+(t-1)*m*2];
				}
				m*=2;
	}
	cout<<"----------------------------------------------------"<<endl;
	cout<<"****  The number of the althletes is:  "<<q<<"  ****"<<endl;
    cout<<"----------------------------------------------------"<<endl;
	cout<<"Zeng Lei ID:0120610680324, Software Engineering 0603"<<endl;
	cout<<endl;
	cout<<"******************************************"<<endl;
	cout<<"**The Arrangement for the althletes is: **"<<endl;
	cout<<"******************************************"<<endl;
	for(int v=1;v<=2*q;v++)
		cout<<setw(2)<<"_";
		cout<<endl;
	for(i=1;i<=q;i++)
	{
		for(int j=1;j<=q;j++)
		cout<<setw(2)<<a[i][j]<<"|"<<" ";
		cout<<endl;
		for(int z=1;z<=2*q;z++)
			cout<<setw(2)<<"_";
	    cout<<endl;
	}
	Continue();
}

void Continue()
{
    char choice;
	cout<<"Continue--'C' "<<endl;
    cout<<"Quit -----'Q' "<<endl;
	cout<<"Input your choice: "<<endl;
	cin>>choice;
	if(choice=='C'||choice=='c' )
	{
	int d;
	cout<<"Please input the Number of athletes!"<<endl;
	cout<<"Number=2^N, and you have to input a integral digital of N:"<<endl;
	cout<<"N=";
	cin>>d;
	Table(d);
	Continue();
	}
	if(choice='Q'||choice=='q')
		system(0);
}

void main()
{
	int N;
	cout<<"Please input the Number of athletes!"<<endl;
	cout<<"Number=2^N, and you have to input a integral digital of N:"<<endl;
	cout<<"N=";
	cin>>N;
	Table(N);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -