#include
<
iostream
>

using
namespace
std;
void
fun(
int
m,
int
*
arr )
...
{
int a = 1,b = 1,index = 1,loop = 0;
for( int i = 0; i <= (m-1)*(m/2); i++ )
...{
if( a >= m ) a = 1;
if( index > m /2 ) index = 1;
if( index == 1 )
...{
loop++;
if( loop > m-1 ) break;
if( i == 1 ) b = m;
else b = a;
if( ( i-1 ) / ( m/2 ) % 2 == 0 ) arr[ 0 ] = a,arr[ 1 ] = m, arr+=2;
else arr[ 0 ] = m,arr[ 1 ] = a,arr+=2;
}
else if( index > 1 && index <= m/2 )
...{
if( b > 1 ) b--;
else b = m-1;
arr[ 0 ] = a,arr[ 1 ] = b,arr+=2;
}
index++,a++;
}
}


int
main()
...
{
cout << "队伍数量:";
int n = 0;
int m = 0;
cin >> n;
if( n % 2 == 0 ) m = n;
else m = n+1;
int* arr = (int*)malloc( m * m * sizeof( int ) );
fun( m, arr );
for( int i = 0; i < m*(m-1); i++ )
...{
if( i % m == 0 ) cout << "第" << (i / m)+1 << "轮" << endl;
if( i % 2 == 0 ) cout << arr[ i ];
else cout << " vs " << arr[ i ] << endl;
}
system("pause");
return 0;
}
这是一个使用C++编写的单循环比赛安排算法。它接受队伍数量作为输入,然后生成并输出比赛的完整赛程。算法通过一个循环来确定每一轮的比赛对阵,并确保每个队伍在比赛过程中与其他所有队伍各比赛一次。

171万+

被折叠的 条评论
为什么被折叠?



