Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.17 KB | None | 0 0
  1. import requests
  2. from zipfile import ZipFile
  3. import random
  4.  
  5.  
  6. # Minimal descending sequence.
  7. def mds(lines):
  8.     m = 0
  9.     n = len(lines)
  10.     lds = [1] * n
  11.     for i in range(n):
  12.         for j in range(i):
  13.             if lines[i] < lines[j] and lds[i] < lds[j] + 1:
  14.                 lds[i] = lds[j] + 1
  15.     for i in range(n):
  16.         if m < lds[i]:
  17.             m = lds[i]
  18.     #    print("minimal descending sequence="+str(m))
  19.     return m
  20.  
  21.  
  22. def clean_tables(lines):
  23.     for i in range(1, len(lines)):
  24.         lines[i] = int(lines[i][:-1])
  25.     lines.pop(0)
  26.     return lines
  27.  
  28.  
  29. def computerounds(lines, a, b):
  30.     roundnumber = 1
  31.     for i in range(a, b):
  32.         if lines[i][1] > lines[i + 1][1]:
  33.             roundnumber += 1
  34.     return roundnumber
  35.  
  36.  
  37. # Python code to sort the lists using the second element of sublists
  38. # Inplace way to sort, use of third variable
  39. def Sort(sub_li):
  40.     l = len(sub_li)
  41.     for i in range(0, l):
  42.         for j in range(0, l - i - 1):
  43.             if (sub_li[j][0] > sub_li[j + 1][0]):
  44.                 tempo = sub_li[j]
  45.                 sub_li[j] = sub_li[j + 1]
  46.                 sub_li[j + 1] = tempo
  47.     return sub_li
  48.  
  49.  
  50. def swap(a, i, j):
  51.     tmp1 = a[j]
  52.     a[j] = a[i]
  53.     a[i] = tmp1
  54.     a[i][0] = i + 1
  55.     a[j][0] = j + 1
  56.     return a
  57.  
  58.  
  59. def tauluja(lines: object) -> object:
  60.     return len(lines)
  61.  
  62.  
  63. def kierroksia(lines):
  64.     a = []
  65.     for i in range(len(lines)):
  66.         a.append([lines[i], i])
  67.     a = Sort(a)
  68.     k = 1
  69.     for i in range(len(a) - 1):
  70.         if a[i][1] < a[i + 1][1]:
  71.             k += 1
  72.     smallestround = len(a)
  73.     for i in range(len(a) - 1):
  74.         for j in range(i + 1, len(a)):
  75.             if a[i][1] > a[j][1]:
  76.                 a = swap(a, i, j)
  77.                 tmp = computerounds(a, 0, len(lines) - 1)
  78.                 if tmp < smallestround:
  79.                     smallestround = tmp
  80.                 a = swap(a, i, j)
  81.     return smallestround
  82.  
  83.  
  84. if __name__ == '__main__':
  85.     lines = [6, 1, 4, 10, 7, 2, 3, 9, 5, 8]
  86.     numberoftables = tauluja(lines)
  87.     smallestround = kierroksia(lines)
  88.     numberofswaps = mds(lines)
  89.     print(numberoftables, smallestround, numberofswaps)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement