728x90
반응형
구현 문제이다.
0 ~ i-1번째 사람들 중에서 i번째 사람보다 키가 큰 사람들 중 제일 작은 사람의 위치를 찾아야 한다.
for j in range(i):
if li[j] > li[i] and li[j] < m:
이 두 줄이 핵심인 것 같다.
for _ in range(int(input())):
a = list(map(int, input().split()))
case, li = a[0], a[1:]
res = 0
for i in range(1, 20):
m, m_idx = max(li)+1, i
for j in range(i):
if li[j] > li[i] and li[j] < m:
m = li[j]
m_idx = j
if m_idx != i:
li = li[:m_idx] + [li[i]] + li[m_idx:i] + li[i+1:]
res += i-m_idx
print(case, res)
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 8806번 Papier kamień nożyczki(python) (0) | 2021.02.21 |
---|---|
백준 알고리즘 10989번 수 정렬하기 3(python) (0) | 2021.02.21 |
백준 알고리즘 2628번 종이자르기(python) (0) | 2021.02.21 |
백준 알고리즘 10610번 30(python) (0) | 2021.02.21 |
백준 알고리즘 2947번 나무 조각(python) (0) | 2021.02.21 |