그리디 알고리즘 문제집을 종료했다. 이후로는 구현에 대해서 공부하고 문제 풀이를 진행할 것이다. 그와 동시에 그리디 한두문제도 같이 풀 생각이다. 부족한 시간을 최대한 활용하도록 노력해야겠다.
백준 7570번 줄 세우기
'''시간초과
import sys
N = int(sys.stdin.readline())
child = list(map(int,sys.stdin.readline().split()))
locate = list()
for i in range(1,len(child)+1):
locate.append(child.index(i)+1)
count = 0
for j in range(len(locate)-1):
if locate[j]>locate[j+1]:
count += 1
print(count)
'''
import sys
N = int(sys.stdin.readline())
child = list(map(int,sys.stdin.readline().split()))
# 0 삽입하여 인덱스 맞춤
child.insert(0,0)
locate=[0]*(N+1)
for i in range(1,len(child)):
locate[child[i]] = i
# 기본적으로 첫 값은 이동할 필요가 없음
count=1
max=0
for j in range(1,len(child)-1):
# 이동할 필요가 없는 수
if(locate[j] < locate[j+1]):
count+=1
if(count>max):
max = count
else:
count=1
print(N-max)
백준 5585번 거스름돈
import sys
N = int(sys.stdin.readline())
coin = [500,100,50,10,5,1]
count = 0
money = 1000-N
for i in coin:
count += money//i
money = money % i
print(count)
백준 10610번 30
import sys
N = sys.stdin.readline().rstrip()
sort_n = sorted(N,reverse=True)
T = ''
for i in sort_n:
T += i
if (int(T)%30) == 0:
print(int(T))
else:
print(-1)