2017 아 리 내 추 필 시험 – 알고리즘 엔지니어
13644 단어 알고리즘
'''
, 。 , 1 ,
32 34 7 33 21 2
13 12 3 11 26 36
16 30 22 1 24 14
20 23 25 5 19 29
27 15 9 17 31 4
6 18 8 10 35 28
, , , , , , 。 , 25-22-3。
30-23-20-16-13-12-3 。 。
'''
'''
:
: , , s s-1 . .
:
1. P ( 0)
2.s=1, 1
3. , 1
4. s=2 , ( =0 ),
5. 1: (s-1)
6. 2: 1, (s-1) , , ; , (s+1)
7. 3-6 , .
'''
def function(L, row, col):
maxlen = 0
P = [[0 for i in range(col)] for j in range(row)]
time = row * col
print('time = ',time)
N = []
s = 1
for i in range(row):
for j in range(col):
ok = True
if i-1 > 0 and L[i][j] > L[i-1][j]:
ok = False
if i+1 < row and L[i][j] > L[i+1][j]:
ok = False
if j-1 > 0 and L[i][j] > L[i][j-1]:
ok = False
if j+1 < col and L[i][j] > L[i][j+1]:
ok = False
if ok:
P[i][j] = s
N.append([i,j])
time -= 1
print('P = ',P)
s += 1
while time > 0:
print(time)
NowN = []
for i in range(len(N)):
NowN.append(N[i])
print('s = ',s)
print('NowN = ',NowN)
for l in NowN:
i = l[0]
j = l[1]
print('i = {}, j = {} '.format(i, j))
if i-1 >= 0:
i_n = i-1
j_n = j
print('i-1 ')
print('i_n = {}, j_n = {} '.format(i_n, j_n))
if(P[i_n][j_n] == 0):
ok = True
if i_n-1 >= 0 and L[i_n][j_n] > L[i_n-1][j_n] and P[i_n-1][j_n] == 0:
ok = False
if j_n-1 >= 0 and L[i_n][j_n] > L[i_n][j_n-1] and P[i_n][j_n-1] == 0:
ok = False
if j_n+1 < col and L[i_n][j_n] > L[i_n][j_n+1] and P[i_n][j_n+1] == 0:
ok = False
if ok:
P[i_n][j_n] = s
N.append([i_n,j_n])
time -= 1
if i+1 < row:
i_n = i+1
j_n = j
print('i+1 ')
print('i_n = {}, j_n = {} '.format(i_n, j_n))
if(P[i_n][j_n] == 0):
ok = True
if i_n+1 < row and L[i_n][j_n] > L[i_n+1][j_n] and P[i_n+1][j_n] == 0:
ok = False
if j_n-1 >= 0 and L[i_n][j_n] > L[i_n][j_n-1] and P[i_n][j_n-1] == 0:
ok = False
if j_n+1 < col and L[i_n][j_n] > L[i_n][j_n+1] and P[i_n][j_n+1] == 0:
ok = False
if ok:
P[i_n][j_n] = s
N.append([i_n,j_n])
time -= 1
if j-1 >= 0:
i_n = i
j_n = j-1
print('j-1 ')
print('i_n = {}, j_n = {} '.format(i_n, j_n))
if(P[i_n][j_n] == 0):
ok = True
if i_n-1 >= 0 and L[i_n][j_n] > L[i_n-1][j_n] and P[i_n-1][j_n] == 0:
ok = False
if i_n+1 < row and L[i_n][j_n] > L[i_n+1][j_n] and P[i_n+1][j_n] == 0:
ok = False
if j_n-1 >= 0 and L[i_n][j_n] > L[i_n][j_n-1] and P[i_n][j_n-1] == 0:
ok = False
if ok:
P[i_n][j_n] = s
N.append([i_n,j_n])
time -= 1
if j+1 < col:
i_n = i
j_n = j+1
print('j+1 ')
print('i_n = {}, j_n = {} '.format(i_n, j_n))
if(P[i_n][j_n] == 0):
ok = True
if i_n-1 >= 0 and L[i_n][j_n] > L[i_n-1][j_n] and P[i_n-1][j_n] == 0:
ok = False
if i_n+1 < row and L[i_n][j_n] > L[i_n+1][j_n] and P[i_n+1][j_n] == 0:
ok = False
if j_n+1 < col and L[i_n][j_n] > L[i_n][j_n+1] and P[i_n][j_n+1] == 0:
ok = False
if ok:
P[i_n][j_n] = s
N.append([i_n,j_n])
time -= 1
N.remove([i,j])
s += 1
return(P,s-1)
L = [[32, 34, 7, 33, 21, 2],
[13, 12, 3, 11, 26, 36],
[16, 30, 22, 1, 24, 14],
[20, 23, 25, 5, 19, 29],
[27, 15, 9, 17, 31, 4],
[6, 18, 8, 10, 35, 28] ]
(P,s) = function(L, 6, 6)
print('P = ',P)
print('s = ',s)
출력 결과: P = [4, 5, 2, 3, 2, 1], [3, 2, 1, 2, 5, 6], [4, 7, 2, 1, 4, 1, 1, 1], [5, 6, 7, 2, 3, 4], [6, 3, 2, 3, 4, 1], [1, 4, 1, 2, 5, 2] s = 7
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
물체 검출의 평가 지표 IoU의 계산 방법Yolo나 SSD 등 물체 검출에서 평가 지표로 사용되는 IoU에 대해 조사했으므로 정리했습니다. IoU (Intersection over Union)는 두 영역이 얼마나 겹치는지를 나타내는 지표입니다. 두 영역의 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.