-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulation.py
More file actions
54 lines (42 loc) · 1.05 KB
/
population.py
File metadata and controls
54 lines (42 loc) · 1.05 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
import math
n,l,r = map(int, input().split())
populations = []
dr = [-1,0,1,0]
dc = [0,1,0,-1]
# DFS 결합?
# 중심 국가의 인접 + 전파
def immigration(pops, i, j):
rot = 1
tot = pops[i][j]
for _ in range(4):
nr = dr[_]+i
nc = dc[_]+j
if(0<=nr<n and 0<=nc<n):
if(l<=abs(pops[i][j]-pops[nr][nc])<=r):
rot+=1
tot+=pops[nr][nc]
else:
continue
print(tot)
if(rot==1):
return False
div = math.trunc(tot/rot)
pops[i][j] = div
for _ in range(4):
nr = dr[_]+i
nc = dc[_]+j
if(0<=nr<n and 0<=nc<n):
pops[nr][nc] = div
return True
for _ in range(n):
populations.append(list(map(int, input().split())))
migrate = 0
for i in range(n):
for j in range(n):
if(immigration(populations, i, j)):
migrate += 1
for i in range(n):
for j in range(n):
print(populations[i][j], end=" ")
print()
print(migrate)