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 Output2 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 ProgrammingUESTC 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
相关文章推荐
- UESTC 1607 大学生足球联赛
- 【构造】CDOJ1607 大学生足球联赛
- Python设计足球联赛赛程表程序的思路与简单实现示例
- 足球联赛赛程算法
- 中超赛程分析(6)--“蛇形排阵”评价指标
- 05年秋季,爱立信研究生足球联赛
- 第十四届男篮世锦赛赛程安排
- 【GRYZ2015】足球联赛
- C++:足球联赛积分系统
- 循环赛程安排
- UESTC - 1264:人民币的构造【规律】
- “IBM南邮杯”南京邮电大学第二届大学生程序设计竞赛之预赛-蛇形矩阵
- 2008北京奥运会足球赛程(男足)
- 循环赛程安排
- BashuOJ - 4479 足球联赛 暴力 水题 重庆一中高2018级竞赛班第四次测试 2016.7.25 Problem 1
- 足球联赛
- 循环赛日程安排(构造、分治)
- 【转】单循环赛赛程安排算法研究
- 我院足球健儿在重庆市第一届“健康校园杯”大学生运动会足球比赛中载誉而归
- 2015 多校联赛 ——HDU5302(构造)