탐욕알고리즘
coin_list = [500, 100, 50, 1]
def min_coin_count(value, coin_list):
total_coin_count = 0
details = list()
coin_list.sort(reverse=True)
for coin in coin_list:
coin_num = value // coin
total_coin_count += coin_num
value -= coin_num * coin
details.append([coin, coin_num])
return total_coin_count, details
print(min_coin_count(4720, coin_list))
boj 2920
a = list(map(int, input().split(' ')))
ascending = True
descending = True
for i in range(1, 8):
if a[i] > a[i - 1]:
descending = False
elif a[i] < a[i - 1]:
ascending = False
if ascending:
print('ascending')
elif descending:
print('descending')
else:
print('mixed')
boj 2798
n, m = list(map(int, input().split(' ')))
data = list(map(int, input().split(' ')))
result = 0
length = len(data)
count = 0
for i in range(0, length):
for j in range(i + 1, length):
for k in range(j + 1, length):
sum_value = data[i] + data[j] + data[k]
if sum_value <= m:
result = max(result, sum_value)
print(result)
boj 1874
n = int(input())
count = 1
stack = []
result = []
for i in range(1, n+1):
data = int(input())
while(count <= data):
stack.append(count)
count += 1
result.append('+')
if stack[-1] == data:
stack.pop()
result.append('-')
else:
print('NO')
exit(0)
print('\n'.join(result))
boj 1966
test_case = int(input())
for _ in range(test_case):
n, m = list(map(int, input().split(' ')))
queue = list(map(int, input().split(' ')))
queue = [(i, idx) for idx, i in enumerate(queue)]
count = 0
while True:
if queue[0][0] == max(queue, key=lambda x: x[0])[0]:
count += 1
if queue[0][1] == m:
print(count)
break
else:
queue.pop(0)
else:
queue.append(queue.pop(0))
boj 5397
test_case = int(input())
for _ in range(test_case):
left_stack = []
right_stack = []
data = input()
for i in data:
if i == '-':
left_stack.pop()
elif i == '<':
if left_stack:
right_stack.append(left_stack.pop())
elif i == '>':
if right_stack:
left_stack.append(right_stack.pop())
else:
left_stack.append(i)
left_stack.extend(reversed(right_stack))
print(''.join(left_stack))
boj 1920
N = int(input())
array = set(map(int, input().split()))
m = int(input())
x = list(map(int, input().split()))
for i in x:
if i not in array:
print('0')
else:
print('1')
boj 4195
def find(x):
if x == parent[x]:
return x
else:
p = find(parent[x])
parent[x] = p
return parent[x]
def union(x, y):
x = find(x)
y = find(y)
if x != y:
parent[y] = x
number[x] += number[y]
test_case = int(input())
for _ in range(test_case):
parent = dict()
number = dict()
f = int(input())
for _ in range(f):
x, y = input().split(' ')
if x not in parent:
parent[x] = x
number[x] = 1
if y not in parent:
parent[y] = y
parent[y] = 1
union(x, y)
print(number[find(x)])