総当たり戦の日程作成
Posted feedbacks - C#
参考資料にあった方法で実装しました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | //http://ja.doukaku.org/149/ 投稿用
using System;
using System.Collections.Generic;
class Program {
static void Main(string[] args) {
int teamCount = int.Parse(args[0]);
List<List<int[]>> leageSchedule = Leage(teamCount);
//出力
for(int day = 0; day < leageSchedule.Count; day++) {
for(int game = 0; game < leageSchedule[day].Count; game++) {
int min = Math.Min(leageSchedule[day][game][0], leageSchedule[day][game][1]);
int max = Math.Max(leageSchedule[day][game][0], leageSchedule[day][game][1]);
Console.Write("{0}-{1} ", min, max);
}
Console.WriteLine();
}
Console.ReadLine();
}
static List<List<int[]>> Leage(int teamCount) {
//チームリスト生成
List<int> teamList = new List<int>();
for(int teamNumber = 1; teamNumber <= teamCount; teamNumber++) {
teamList.Add(teamNumber);
}
//各組み合わせを生成
List<List<int[]>> leageSchedule = new List<List<int[]>>();
for(int day = 0; day < teamCount - 1; day++) {
List<int[]> daySchedule = new List<int[]>();
daySchedule.Add(new int[] { teamList[0], teamList[1] });
for(int game = 1; game <= teamCount / 2 - 1; game++) {
daySchedule.Add(new int[] { teamList[1 + game], teamList[teamList.Count - game] });
}
leageSchedule.Add(daySchedule);
teamList.Add(teamList[1]);
teamList.RemoveAt(1);
}
return leageSchedule;
}
}
|


ryugate
#5661()
Rating2/2=1.00
see: カークマンの組分け
[ reply ]