본문 바로가기

프로그래머스 - 탐욕법(Greedy) - 체육복 프로그래머스 - 탐욕법(Greedy) - 체육복 작성언어: Python3def solution(n, lost, reserve): temp = list(set(lost + reserve)) answer = n - len(temp) temp = []​ for i in lost: if(i in reserve): answer += 1 reserve.remove(i) temp.append(i) lost = list(set(lost) - set(temp)) for i in lost: if(i-1 in reserve): answer += 2 reserve.remove(i-1) elif(i+1 in reserve): answer += 2 reserve.remove(i+1)​ answer += len(reserve)​ ..
BOJ 1541 - 잃어버린 괄호 https://www.acmicpc.net/problem/1541 BOJ 1541 - 잃어버린 괄호 작성언어: Python3exp = input().split('-')itemList = []​for t in exp: temp = list(map(int, t.split('+'))) itemList.append(sum(temp))​total = itemList[0]​for item in itemList[1:]: total -= item​print(total)pc 환경에서 코드를 보는 것을 권장합니다.
BOJ 11399 - ATM https://www.acmicpc.net/problem/11399 BOJ 11399 - ATM 작성언어: Python3n = int(input())time = list(map(int, input().split()))totalTime = 0cumulativeTime = 0​time.sort()​for t in time: cumulativeTime += t totalTime += cumulativeTime​print(totalTime)pc 환경에서 코드를 보는 것을 권장합니다.
BOJ 1931 - 회의실배정 https://www.acmicpc.net/problem/1931 BOJ 1931 - 회의실배정 작성언어: Python3xxxxxxxxxxn = int(input())conf = []​for i in range(n): conf.append(list(map(int, input().split())))conf.sort(key=lambda x : [x[1],x[0]])​cnt = 1j = 0​for i in range(1, len(conf)): if(conf[i][0] >= conf[j][1]): cnt += 1 j = i​print(cnt)pc 환경에서 코드를 보는 것을 권장합니다.
BOJ 11047 - 동전 0 https://www.acmicpc.net/problem/11047 BOJ 11047 - 동전 0 작성언어: Python3n, k = map(int, input().split())a = []cnt = 0​for i in range(n): a.append(int(input()))a.reverse()​for money in a: if(money
BOJ 1011 - Fly me to the Alpha Centauri https://www.acmicpc.net/problem/1011 BOJ 1011 - Fly me to the Alpha Centauri 작성언어: Python3xxxxxxxxxximport math​t = int(input())​for i in range(t): start, end = map(int, input().split()) dist = end - start k = 1 while(k*k
BOJ 2775 - 부녀회장이 될테야 https://www.acmicpc.net/problem/2775 BOJ 2775 - 부녀회장이 될테야 작성언어: Python3t = int(input())d = [[0]*15 for i in range(15)]​for i in range(1, 15): d[0][i] = ifor i in range(1, 15): for j in range(1, 15): d[i][j] = d[i][j-1] + d[i-1][j]​for i in range(t): k = int(input()) n = int(input()) print(d[k][n])pc 환경에서 코드를 보는 것을 권장합니다.
BOJ 10250 - ACM 호텔 https://www.acmicpc.net/problem/10250 BOJ 10250 - ACM 호텔 작성언어: Python3xxxxxxxxxxt = int(input())​for i in range(t): h, w, n = map(int, input().split()) if(n % h): room = (n % h * 100) + (int(n / h) + 1) else: room = (h * 100) + int(n / h)​ print(room)pc 환경에서 코드를 보는 것을 권장합니다.