fork download
  1. def brute_force(lst, norm_func):
  2. # Начальное состояние: все работы выполняет работник №2
  3. min_norm = norm_func(0, sum(lst), 0)
  4. result = (0,len(lst))
  5.  
  6. for K in range(1,len(lst)-2):
  7. for L in range(K+1, len(lst)-1):
  8. v1,v2,v3 = sum(lst[0:K]), sum(lst[K:L]), sum(lst[L:])
  9. nrm = norm_func(v1,v2,v3)
  10. if nrm < min_norm:
  11. print("New candidate: norm, K,L", nrm, K,L)
  12. min_norm = nrm
  13. result = (K,L)
  14. return result
  15.  
  16. # Вспомогательная функция, печатает назначения работ.
  17. def print_result(test, K,L):
  18. print((test[0:K], sum(test[0:K])),(test[K:L], sum(test[K:L])),(test[L:], sum(test[L:])))
  19.  
  20. def minimax(v1,v2,v3):
  21. return max(abs(v1-v2),abs(v2-v3), abs(v3-v1))
  22.  
  23. def abs_sum(v1,v2,v3):
  24. return abs(v1-v2)+abs(v2-v3)+abs(v3-v1)
  25.  
  26. test=[604,126,596,558,479,633,991,276,818,781,430,748,66,273,97,171,162,220,915,863,979,759,747,865,582,686,591,641,314,380,297,673,692,195,259,190,596,688,115,942,366,3,54,994,637,887,351,697,223,812,69,34,645,375,74,26,221,558,868,352,392,758,307,786,652,417,465,614,243,554,365,700,386,138,551,495,249,767,300,572,327,219,23,49,55,79,81,953,749,77,742,727,110,17,736,137,913,259,800,5]
  27.  
  28. K,L = brute_force(test, minimax)
  29. print_result(test,K,L)
Success #stdin #stdout 0.04s 9312KB
stdin
Standard input is empty
stdout
New candidate: norm, K,L 45157 1 2
New candidate: norm, K,L 44083 1 3
New candidate: norm, K,L 43525 1 4
New candidate: norm, K,L 43046 1 5
New candidate: norm, K,L 42413 1 6
New candidate: norm, K,L 41422 1 7
New candidate: norm, K,L 41146 1 8
New candidate: norm, K,L 40328 1 9
New candidate: norm, K,L 39547 1 10
New candidate: norm, K,L 39117 1 11
New candidate: norm, K,L 38369 1 12
New candidate: norm, K,L 38303 1 13
New candidate: norm, K,L 38030 1 14
New candidate: norm, K,L 37933 1 15
New candidate: norm, K,L 37762 1 16
New candidate: norm, K,L 37600 1 17
New candidate: norm, K,L 37380 1 18
New candidate: norm, K,L 36465 1 19
New candidate: norm, K,L 35602 1 20
New candidate: norm, K,L 34623 1 21
New candidate: norm, K,L 33864 1 22
New candidate: norm, K,L 33117 1 23
New candidate: norm, K,L 32252 1 24
New candidate: norm, K,L 31670 1 25
New candidate: norm, K,L 30984 1 26
New candidate: norm, K,L 30393 1 27
New candidate: norm, K,L 29752 1 28
New candidate: norm, K,L 29438 1 29
New candidate: norm, K,L 29058 1 30
New candidate: norm, K,L 28761 1 31
New candidate: norm, K,L 28088 1 32
New candidate: norm, K,L 27396 1 33
New candidate: norm, K,L 27201 1 34
New candidate: norm, K,L 26942 1 35
New candidate: norm, K,L 26752 1 36
New candidate: norm, K,L 26156 1 37
New candidate: norm, K,L 25468 1 38
New candidate: norm, K,L 25353 1 39
New candidate: norm, K,L 24411 1 40
New candidate: norm, K,L 24045 1 41
New candidate: norm, K,L 24042 1 42
New candidate: norm, K,L 23988 1 43
New candidate: norm, K,L 22994 1 44
New candidate: norm, K,L 22357 1 45
New candidate: norm, K,L 22231 2 45
New candidate: norm, K,L 21635 3 45
New candidate: norm, K,L 21287 3 46
New candidate: norm, K,L 21077 4 45
New candidate: norm, K,L 20190 4 46
New candidate: norm, K,L 19711 5 46
New candidate: norm, K,L 19564 5 47
New candidate: norm, K,L 19078 6 46
New candidate: norm, K,L 18727 6 47
New candidate: norm, K,L 18087 7 46
New candidate: norm, K,L 17736 7 47
New candidate: norm, K,L 17039 7 48
New candidate: norm, K,L 16763 8 48
New candidate: norm, K,L 16684 8 49
New candidate: norm, K,L 16642 9 47
New candidate: norm, K,L 15945 9 48
New candidate: norm, K,L 15722 9 49
New candidate: norm, K,L 15164 10 48
New candidate: norm, K,L 14941 10 49
New candidate: norm, K,L 14298 10 50
New candidate: norm, K,L 13699 11 50
New candidate: norm, K,L 13630 11 51
New candidate: norm, K,L 13596 11 52
New candidate: norm, K,L 12951 12 50
New candidate: norm, K,L 12882 12 51
New candidate: norm, K,L 12848 12 52
New candidate: norm, K,L 12690 12 53
New candidate: norm, K,L 12558 13 53
New candidate: norm, K,L 12543 14 51
New candidate: norm, K,L 12509 14 52
New candidate: norm, K,L 12012 14 53
New candidate: norm, K,L 11818 15 53
New candidate: norm, K,L 11596 16 53
New candidate: norm, K,L 11434 17 53
New candidate: norm, K,L 11214 18 53
New candidate: norm, K,L 11087 18 54
New candidate: norm, K,L 11047 19 50
New candidate: norm, K,L 10978 19 51
New candidate: norm, K,L 10944 19 52
New candidate: norm, K,L 10299 19 53
New candidate: norm, K,L 9924 19 54
New candidate: norm, K,L 9850 19 55
New candidate: norm, K,L 9824 19 56
New candidate: norm, K,L 9603 19 57
New candidate: norm, K,L 9436 20 53
New candidate: norm, K,L 9061 20 54
New candidate: norm, K,L 8987 20 55
New candidate: norm, K,L 8961 20 56
New candidate: norm, K,L 8740 20 57
New candidate: norm, K,L 8410 20 58
New candidate: norm, K,L 8082 21 54
New candidate: norm, K,L 8008 21 55
New candidate: norm, K,L 7982 21 56
New candidate: norm, K,L 7761 21 57
New candidate: norm, K,L 7203 21 58
New candidate: norm, K,L 7002 22 57
New candidate: norm, K,L 6444 22 58
New candidate: norm, K,L 5802 22 59
New candidate: norm, K,L 5697 23 58
New candidate: norm, K,L 4829 23 59
New candidate: norm, K,L 4660 23 60
New candidate: norm, K,L 3964 24 59
New candidate: norm, K,L 3612 24 60
New candidate: norm, K,L 3322 24 61
New candidate: norm, K,L 3030 25 60
New candidate: norm, K,L 2638 25 61
New candidate: norm, K,L 2344 26 60
New candidate: norm, K,L 1952 26 61
New candidate: norm, K,L 1544 26 62
New candidate: norm, K,L 603 27 62
([604, 126, 596, 558, 479, 633, 991, 276, 818, 781, 430, 748, 66, 273, 97, 171, 162, 220, 915, 863, 979, 759, 747, 865, 582, 686, 591], 15016) ([641, 314, 380, 297, 673, 692, 195, 259, 190, 596, 688, 115, 942, 366, 3, 54, 994, 637, 887, 351, 697, 223, 812, 69, 34, 645, 375, 74, 26, 221, 558, 868, 352, 392, 758], 15378) ([307, 786, 652, 417, 465, 614, 243, 554, 365, 700, 386, 138, 551, 495, 249, 767, 300, 572, 327, 219, 23, 49, 55, 79, 81, 953, 749, 77, 742, 727, 110, 17, 736, 137, 913, 259, 800, 5], 15619)