강의

멘토링

커뮤니티

Inflearn Community Q&A

chj789510660's profile image
chj789510660

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

10. Inverse sequence (greedy)

반례가 있을 까요?

Written on

·

200

0

이분 탐색 및 결정알고리즘은 lt와 rt가 주어지고 범위가 보일 때 사용하는지를 생각하면서 풀어야 겠다는 걸 알겠는데 그리디는 그냥 느낌 오는대로 막 풀었는데 어떤 생각을 해야 하나요? 그리고 밑에 제가 답지 안보고 푼 정답인데 반례가 있을 까요??

a = int(input())
b = list(map(int, input().split()))

c = [0] * a

for i in range(a):
count = -1
for t in range(a):
if c[t] == 0:
count += 1
if b[i] == count:
if c[t] == 0:
c[t] = i + 1
break
else:
t += 1

for k in range(a):
if c[k] == 0:
c[k] = a

print(c)
반례코테 준비 같이 해요! python

Answer

This question is waiting for answers
Be the first to answer!
chj789510660's profile image
chj789510660

asked

Ask a question