單迴圈賽競賽隔最大的近似演算法

2021-05-24 05:30:12 字數 4053 閱讀 6669

單迴圈賽,每個隊參加前後兩場比賽之間的距離最大,這就是這個問題的要求。

這個問題,使用簡單回溯,剪剪枝好像可以,但是要當n很大的時候就很為難,速度什麼的成了問題。所以這裡,我使用了近似演算法。

觀察問題,發現這是乙個對稱矩陣的問題,那麼我有幾條啟發式規則:

(1)插入矩陣的元素,不應該和前 m 的元素同行很列。

這個,很簡單可以理解,這是為了使最小間距得意保證。

(2)插入的位置,應盡可能在行或者列上佔據更多的空格。

這個,有一點難理解,主要是先插入的元素理應佔有利位置,這樣越往後,差距變大的可能性就提高了。

否則當後面插入時,差距就會變小

(3)插入位置理應和個行列產生最大的行間距。

這個也好理解,主要是為了保證最小間距最大。

(4)插入位置理應靠近上三角的中心。

這個還是為了保證插入時能很有效的滿意。

之後,我們便是不斷地嘗試(1)裡面提到的m的值。這裡,我們先來估計一下m的上界吧。假設最小間距為m,那麼(i,j) 先比賽,比賽之後就是(i,k)比賽,這樣必須除了i,j,k之外還至少有2m個球隊,所以 n >= 2m + 3;也就是 m <=  [(n-3)/2];

這樣,我們便開始從m的上界開始,向下檢索。

結果如下:(5 到 49,result是結果,der_result_for_ideal_bound 是與理想上界的差,cpu_clock是消耗的cpu時鐘數)

5: result = 2 , der_result_for_ideal_bound = 0 , cpu_clock = 1

6: result = 2 , der_result_for_ideal_bound = 0 , cpu_clock = 10

7: result = 2 , der_result_for_ideal_bound = 1 , cpu_clock = 10

8: result = 2 , der_result_for_ideal_bound = 1 , cpu_clock = 10

9: result = 3 , der_result_for_ideal_bound = 1 , cpu_clock = 10

10: result = 3 , der_result_for_ideal_bound = 1 , cpu_clock = 20

11: result = 4 , der_result_for_ideal_bound = 1 , cpu_clock = 20

12: result = 4 , der_result_for_ideal_bound = 1 , cpu_clock = 20

13: result = 4 , der_result_for_ideal_bound = 2 , cpu_clock = 50

14: result = 5 , der_result_for_ideal_bound = 1 , cpu_clock = 40

15: result = 5 , der_result_for_ideal_bound = 2 , cpu_clock = 80

16: result = 5 , der_result_for_ideal_bound = 2 , cpu_clock = 120

17: result = 6 , der_result_for_ideal_bound = 2 , cpu_clock = 130

18: result = 6 , der_result_for_ideal_bound = 2 , cpu_clock = 210

19: result = 6 , der_result_for_ideal_bound = 3 , cpu_clock = 320

20: result = 7 , der_result_for_ideal_bound = 2 , cpu_clock = 260

21: result = 7 , der_result_for_ideal_bound = 3 , cpu_clock = 420

22: result = 7 , der_result_for_ideal_bound = 3 , cpu_clock = 580

23: result = 8 , der_result_for_ideal_bound = 3 , cpu_clock = 630

24: result = 8 , der_result_for_ideal_bound = 3 , cpu_clock = 660

25: result = 8 , der_result_for_ideal_bound = 4 , cpu_clock = 1270

26: result = 9 , der_result_for_ideal_bound = 3 , cpu_clock = 1070

27: result = 10 , der_result_for_ideal_bound = 3 , cpu_clock = 1040

28: result = 10 , der_result_for_ideal_bound = 3 , cpu_clock = 1350

29: result = 10 , der_result_for_ideal_bound = 4 , cpu_clock = 2120

30: result = 11 , der_result_for_ideal_bound = 3 , cpu_clock = 6260

31: result = 11 , der_result_for_ideal_bound = 4 , cpu_clock = 2700

32: result = 11 , der_result_for_ideal_bound = 4 , cpu_clock = 2950

33: result = 11 , der_result_for_ideal_bound = 5 , cpu_clock = 8080

34: result = 12 , der_result_for_ideal_bound = 4 , cpu_clock = 4310

35: result = 13 , der_result_for_ideal_bound = 4 , cpu_clock = 4110

36: result = 13 , der_result_for_ideal_bound = 4 , cpu_clock = 7970

37: result = 14 , der_result_for_ideal_bound = 4 , cpu_clock = 5230

38: result = 13 , der_result_for_ideal_bound = 5 , cpu_clock = 9520

39: result = 14 , der_result_for_ideal_bound = 5 , cpu_clock = 8910

40: result = 14 , der_result_for_ideal_bound = 5 , cpu_clock = 14410

41: result = 15 , der_result_for_ideal_bound = 5 , cpu_clock = 20310

42: result = 14 , der_result_for_ideal_bound = 6 , cpu_clock = 25880

43: result = 15 , der_result_for_ideal_bound = 6 , cpu_clock = 27760

44: result = 16 , der_result_for_ideal_bound = 5 , cpu_clock = 27790

45: result = 14 , der_result_for_ideal_bound = 8 , cpu_clock = 65320

46: result = 16 , der_result_for_ideal_bound = 6 , cpu_clock = 45770

47: result = 16 , der_result_for_ideal_bound = 7 , cpu_clock = 49920

48: result = 17 , der_result_for_ideal_bound = 6 , cpu_clock = 56730

49: result = 17 , der_result_for_ideal_bound = 7 , cpu_clock = 60300

total_clock:1004671

桌球單迴圈賽 桌球單迴圈比賽規則

桌球單迴圈比賽規則 一 桌球單迴圈比賽規則 迴圈賽是桌球競賽的一種基本比賽辦法。所謂迴圈賽就是使參加比賽的各力互相之間都直接比賽一次,又稱桌球單迴圈賽。讓我們一起看看桌球單迴圈比賽規則吧!桌球單迴圈賽比賽輪次的計算 如果參加的隊數是偶數,則比賽輪數為隊數減1。例如 8個隊參加比賽,比賽輪數為8 1 ...

單迴圈賽程安排問題

首先,來解釋一下,什麼是單迴圈問題,其實,這是乙個我們在實現中經常遇到的問題。問題描述 賽程問題 有n個運動員進行單迴圈賽,即兩個運動員都要與其他所有運動員比賽一次。要求每個運動員每天只進行一次比賽,且整個賽程在n 1天內結束,運動員編號由1到n 注 n 2 k 解題思想 看到這個問題,我們的第一種...

單迴圈賽程安排問題

首先,來解釋一下,什麼是單迴圈問題,其實,這是乙個我們在實現中經常遇到的問題。問題描述 賽程問題 有n個運動員進行單迴圈賽,即兩個運動員都要與其他所有運動員比賽一次。要求每個運動員每天只進行一次比賽,且整個賽程在n 1天內結束,運動員編號由1到n 注 n 2 k 解題思想 看到這個問題,我們的第一種...