-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2020 hashcode.py
More file actions
87 lines (71 loc) · 1.97 KB
/
2020 hashcode.py
File metadata and controls
87 lines (71 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import random
file1 = open("f.txt","r")
lines = file1.readlines()
line1 = lines[0].split()
line2 = lines[1].split(" ")
global BOOKS
global DAY
global DEADLINE
global TOTALBOOKS
global TOTALLIB
BOOKS = list(line2)
DEADLINE = int(line1[2])
TOTALBOOKS = line2
TOTALLIB = line1[1]
BOOKS[len(BOOKS)-1] = str(546)
class library():
def __init__(self,libID,books,signup,uniqueBooks,maxSend):
self.libID = libID
self.open = False
self.books = books
self.signup = signup
self.uniqueBooks = uniqueBooks
self.max = maxSend
self.slots = (DEADLINE - self.signup) * self.max
def slots(self) :
pass
librarys = []
count = 0
count2 = 0
for x in lines[2:]:
line = list(x.split())
count += 1
#print(line)
if line == []:
break
if count == 1:
lib = library(count2,[],int(line[1]),None,int(line[2]))
count2 += 1
librarys.append(lib)
else:
#print(TOTALBOOKS[int(book)])
#score = TOTALBOOKS[int(book)]
#print(score)
#book = (int(score), book)
#book = (book)
#print(book)
librarys[count2-1].books.append(x.split(" "))
#sorted(librarys[count2-1].books)
count = 0
from operator import itemgetter
sentbooks = []
sublibraries =[]
submitFile = open("f_ans.txt","w+")
libraries = []
while DEADLINE > 0:
numb = random.randint(0,len(librarys)-1)
DEADLINE = DEADLINE - librarys[numb].signup
libraries.append((numb,librarys[numb].books))
submitFile.write(str(len(libraries)))
submitFile.write("\n")
for i in libraries:
submitFile.write("%s %s " %(i[0],str(len(i[1]))))
submitFile.write("\n")
for x in i[1]:
count = 0
for l in x:
if count < 1:
count += 1
submitFile.write(l)
submitFile.write(" ")
submitFile.write("\n")