From 429fb1c35d47879ef83ca34af5847dd03e90395e Mon Sep 17 00:00:00 2001 From: Pronoy Mandal Date: Wed, 21 Jun 2023 11:49:52 +0530 Subject: [PATCH] Update uva10026.py A simpler solution for the Shoemaker's problem --- .../uva10026/uva10026.py | 44 ++++++------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/algorithms/the-algorithm-design-manual/programming-challenges/uva10026/uva10026.py b/algorithms/the-algorithm-design-manual/programming-challenges/uva10026/uva10026.py index 7e38dc8..58602d4 100644 --- a/algorithms/the-algorithm-design-manual/programming-challenges/uva10026/uva10026.py +++ b/algorithms/the-algorithm-design-manual/programming-challenges/uva10026/uva10026.py @@ -1,31 +1,13 @@ -nn = int(input()) - - -class Job: - def __init__(self, i, t, f): - self.i = i - self.t = t - self.f = f - - def __lt__(self, other): - return self.f * other.t > self.t * other.f - - def __str__(self): - return f'{self.i}' - - -for ii in range(nn): - input() - if ii != 0: - print('') - - n = int(input()) - - jobs = [] - - for i in range(n): - jobs.append(Job(i+1, *map(int, input().split()))) - - jobs.sort() - - print(*jobs) +def result(jobs): + return ' '.join(str(x[1]) for x in sorted(jobs)) + +jqs = [] +for _ in range(int(input())): + input() + jobs = [] + for i in range(1, int(input()) + 1): + T, S = map(int, input().split()) + jobs.append((T / S, i)) + jqs.append(jobs) + +print('\n\n'.join(result(jobs) for jobs in jqs))