-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathomtrek.py
107 lines (90 loc) · 2.42 KB
/
omtrek.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""Opgave omtrek"""
"""Author: Philippe Asselbergh"""
"""Date:30/01/2016"""
def berekenOmtrek (grid_array):
max_x =len(grid_array) -1
max_y =len(grid_array[0]) -1
omtrek = 0
x = 0
while x <= max_x +1:
y = 0
while y <= max_y +1:
###
if x == 0:
xp = 0
else:
if y != max_y+1:
xp = grid_array[x-1][y]
else:
xp = 0
if y == 0:
yp = 0
else:
if x != max_x +1:
yp = grid_array[x][y-1]
else:
yp = 0
if x == max_x+1:
a = 0
elif y == max_y +1:
a = 0
else:
a = grid_array[x][y]
## a en xp en yp
if a != xp:
omtrek = omtrek +1
if a != yp:
omtrek = omtrek +1
###
y = y + 1
x = x +1
return omtrek
def oppervlakte(n):
opp=0
maxX= len(n)
maxY= len(n[0])
for x in range(maxX):
for y in range(maxY):
opp = opp + n[x][y]
return opp
def xComponentRechthoek(ts):
maxX=0
for i in range(len(ts)):
maxX=max(int(ts[i][0])+int(ts[i][2]),maxX)
return maxX
def yComponentRechthoek(ts):
maxY=0
for i in range(len(ts)):
maxY=max(int(ts[i][1])+int(ts[i][3]),maxY)
return maxY
"""omtrek"""
out1=[]
"""oppervlakte"""
out2=[]
"""Aantal testgevallen"""
n = int(raw_input())
"""Getallen inlezen"""
for j in range(n):
"""Aantal rechthoeken in testgeval"""
aantalRechthoek = int(raw_input())
ts = [[0 for x in range(4)] for x in range(aantalRechthoek)]
for i in range(aantalRechthoek):
ts[i] = raw_input().split( )
x = xComponentRechthoek(ts)
y = yComponentRechthoek(ts)
num_list = [[0 for z in range(y)] for z in range(x)]
for i in range(aantalRechthoek):
for j in range(int(ts[i][0]),int(ts[i][0])+int(ts[i][2])):
for k in range(int(ts[i][1]),int(ts[i][1])+int(ts[i][3])):
num_list[j][k] = 1
"""bereken omtrek"""
om = berekenOmtrek(num_list)
"""bereken oppervlakte"""
op = oppervlakte(num_list)
"""omtrek"""
out1.append(om)
"""oppervlakte"""
out2.append(op)
for x in range(n):
"""nummer _ oppervlakte _ omtrek"""
print x+1, out2[x] , out1[x]