-
Notifications
You must be signed in to change notification settings - Fork 0
/
3b.py
58 lines (41 loc) · 1.03 KB
/
3b.py
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
file_name = "3a.txt"
import numpy as np
def process(x):
d = 0
t = 0
shapes = []
for r in x:
r = r.replace(':','').replace('\n','').split(' ')
l = int(r[2].split(',')[0])
t = int(r[2].split(',')[1])
w = int(r[3].split('x')[0])
h = int(r[3].split('x')[1])
claimid = int(r[0].replace('#',''))
area = w * h
shapes.append( [l,t,w,h,area,claimid] )
#print(shapes)
totalw = max([i[0] + i[2] for i in shapes ])
totalh = max([i[1] + i[3] for i in shapes ])
print( totalw, totalh )
base_arr = np.zeros(( totalh, totalw ))
for s in shapes:
l,t,w,h,area,claimid = s
for r in range(t,t+h ):
for c in range(l, l+w):
if base_arr.item((r,c)) != 0:
base_arr.itemset((r,c), -1)
else:
base_arr.itemset((r,c), claimid)
for s in shapes:
l,t,w,h, area,claimid = s
if np.count_nonzero(base_arr == claimid ) == area:
print( "found it!! ", claimid )
return
print( "count ", count )
return
def main():
with open(file_name, 'r') as f:
x = f.readlines()
print(len(x))
process(x)
main()