From 73d8f85b6fed9e707f8f2c63e8c704d9ea0b0609 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Thu, 12 Sep 2019 21:59:31 +0200 Subject: [PATCH] Stuff not committed --- gnomes.py | 37 ++++++++++++++++++++++ gnomes.txt | 3 ++ promo.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ promo.txt | 9 ++++++ 4 files changed, 140 insertions(+) create mode 100644 gnomes.py create mode 100644 gnomes.txt create mode 100644 promo.py create mode 100644 promo.txt diff --git a/gnomes.py b/gnomes.py new file mode 100644 index 0000000..135520e --- /dev/null +++ b/gnomes.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import heapq + +def gnome_seq(A, H, n): + R = [] + i = 0 + while i < len(A): + if not len(H) == 0 and H[0] < A[i]: + R.append(heapq.heappop(H)) + else: + R.append(A[i]) + i += 1 + + while len(H) > 0: + R.append(heapq.heappop(H)) + return R + + +if __name__ == "__main__": + string = input().split() + n = int(string[0]) + m = int(string[1]) + A = [] + E = [False] * (n+1) + for i in range(m): + num = int(input()) + A.append(num) + E[num] = True + H = [] + for i in range(1, n + 1): + if not E[i]: + heapq.heappush(H, i) + + for n in gnome_seq(A, H, n): + print(n) + diff --git a/gnomes.txt b/gnomes.txt new file mode 100644 index 0000000..3d6a8e5 --- /dev/null +++ b/gnomes.txt @@ -0,0 +1,3 @@ +1 1 +1 + diff --git a/promo.py b/promo.py new file mode 100644 index 0000000..d3b4351 --- /dev/null +++ b/promo.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 + +import queue + +def criteria(a): + return a[0] + +def promote(G, Ginv, a, b): + Depth = [None] * len(G) + + Q = queue.Queue(maxsize=len(G)) + + print(Ginv) + + for i in range(len(G)): + if len(Ginv[i]) == 0: + Q.put(i) + Depth[i] = 0 + + print(G) + + while not Q.empty(): + u = Q.get() + for v in G[u]: + if Depth[v] is None: + Depth[v] = Depth[u] + 1 + Q.put(v) + + for i in range(len(Depth)): + Depth[i] = (Depth[i], i) + + print(Depth) + + Depth.sort(key=criteria, reverse=True) + + sums = [0] + p = None + for i in range(0, len(Depth)): + if p is None or p == Depth[i][0]: + sums[-1] += 1 + p = Depth[i][0] + else: + sums.append(0) + p = None + + ss = 0 + i = 0 + while i < len(sums) and ss + sums[i] <= a: + ss = ss + sums[i] + i += 1 + + prom_A = ss + + while i < len(sums) and ss + sums[i] <= b: + ss = ss + sums[i] + i += 1 + + prom_B = ss + + if ss < b: + ss = ss + sums[i] + + no_prom = ss + + return (prom_A, prom_B, no_prom) + +if __name__ == "__main__": + s = input().split() + a = int(s[0]) + b = int(s[1]) + n_emp = int(s[2]) + n_prec = int(s[3]) + + G = [] + Ginv = [] + for i in range(n_emp): + G.append([]) + Ginv.append([]) + + for i in range(n_prec): + s = input().split() + x = int(s[0]) + y = int(s[1]) + G[x].append(y) + Ginv[y].append(x) + + x, y, z = promote(G, Ginv, a, b) + print(x) + print(y) + print(z) + diff --git a/promo.txt b/promo.txt new file mode 100644 index 0000000..9bb6a9e --- /dev/null +++ b/promo.txt @@ -0,0 +1,9 @@ +3 4 7 8 +0 4 +1 2 +1 5 +5 2 +6 4 +0 1 +2 3 +4 5