您的位置:首页 > 产品设计 > UI/UE

UESTC 1607 大学生足球联赛 构造、蛇形安排赛程表

2017-06-11 16:47 323 查看

大学生足球联赛

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)

Submit  Status

大学生足球联赛火热来袭,共有N(N为偶数)支大学球队报名参加了这次比赛。联赛采取单循环制,每只球队需要跟其他N−1支球队交手一次。赛事共有N−1轮,每轮有N2场比赛,每一轮每支球队都得出场比赛。你是本届赛事的负责人,队伍的编号为1~N,请你安排一个N支球队N−1轮的赛程表。

Input

一个整数N,代表报名参赛的大学球队数。(2≤N≤66)



Output

输出共有N−1行,第ii行代表第i轮的对阵情况。

对于每一行,共有N个数,用空格相隔,其中第2×j−1个数和第2×j个数代表该轮第j组比赛对阵。

赛程表有很多种可能,你只需输出任意一组合法的赛程表即可。

Sample input and output

Sample Input Sample Output

2                                    1 2

4                                    1 2 3 4

                                      1 3 2 4

                                      1 4 2 3

6                                    1 2 3 4 5 6

                                      1 3 2 5 4 6

                                      1 4 2 6 3 5

                                      1 5 2 4 3 6

                                      1 6 2 3 4 5

Hint

样例1,2支球队1轮赛程表为:

第1轮:1−2

样例2,4支球队3轮赛程表为:

第1轮:1−2 3−4

第2轮:1−3 2−4

第3轮:1−4 2−3

样例3,6支球队5轮赛程表为:

第1轮:1−2 3−4 5−6

第2轮:1−3 2−5 4−6

第3轮:1−4 2−6 3−5

第4轮:1−5 2−4 3−6

第5轮:1−6 2−3 4−5

Source

2017 UESTC Training for Dynamic Programming

UESTC 1607 大学生足球联赛

My Solution

构造法:蛇形安排赛程表

将1-N排成两竖列,每一轮同一行的为对手

保持1的位置不变,其他位置按顺(逆)时方向依次旋转

1    6          1    2          1    3          1    4          1    5      

2    5          3    6          4    2          5    3          6    4      

3    4          4    5          5    6          6    2          2    3

1             N

2           N-1

3           N-2

.              .

.              .

.              .

N/2    N/2+1

时间复杂度 O(n^2)

空间复杂度 O(n)

#include <iostream>
#include <cstdio>

using namespace std;
typedef long long LL;
const int MAXN = 66 + 8;

int a[MAXN][2];

int main()
{
#ifdef LOCAL
freopen("a.txt", "r", stdin);
//freopen("a.out", "w", stdout);
int T = 1;
while(T--){
#endif // LOCAL
//ios::sync_with_stdio(false); cin.tie(0);

int n, i, j, t;
//cin >> n;
scanf("%d", &n);
for(i = 1; i <= n/2; i++){
a[i][0] = i;
a[i][1] = n - i + 1;
}
for(i = 1; i < n; i++){
/*
for(j = 1; j <= n/2; j++){
printf("%d %d\n", a[j][0], a[j][1]);
}
putchar('\n');
*/
for(j = 1; j <= n/2; j++){
if(j != 1) putchar(' ');
printf("%d %d", a[j][0], a[j][1]);
}
putchar('\n');

t = a[2][0];
for(j = 2; j < n/2; j++){
a[j][0] = a[j+1][0];
}
a[n/2][0] = a[n/2][1];
for(j = n/2; j >= 2; j--){
a[j][1] = a[j-1][1];
}
a[1][1] = t;

}

#ifdef LOCAL
cout << endl;
}
#endif // LOCAL
return 0;
}


  Thank you!

                                                                                                           
                                ------from ProLights
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: