K

@kimjuha19

나무 자르기

Python
5 months ago
trees = [20, 15, 10, 17] M = 7 left, right = 0, max(trees) answer = 0 while left <= right: mid = (left + right) // 2 total = 0

카드 뒤집기

Python
5 months ago
cards = list(range(1, 21)) a, b = 5, 10 cards[a-1:b] = cards[a-1:b][::-1] print(cards)

설탕 배달

Python
5 months ago
N = 11 F = 5 T = 3 bags = 0 while N >= 0: if N % F == 0: bags += N // F break N -= T

카드

Python
5 months ago
arr = [1,2,3,4,5,6] for i in range(len(arr)-1-1-1): if arr[i] % 2 != 0: arr.remove(arr[i]) while len(arr) > 1: arr.remove(arr[0]) arr.append(arr[0]) arr.remove(arr[0])

보석 도둑(2)

Python
5 months ago
jewel = [(10, 100), (15, 200), (20, 150)] weight = 25 jewel.sort(key=lambda x: x[1] / x[0], reverse=True) total_weight = 0 total_value = 0 for w, v in jewel: if total_weight + w <= weight:

문자열 폭발

Python
5 months ago
length = "mirkovC4nizCC44" boom = "C4" while boom in length: length = length.replace(boom, "") print(length)

부분합

Python
5 months ago
S = 15 arr = [5, 1, 3, 5, 10, 7, 4, 9, 2, 8] start = 0 current_sum = 0 min_len = len(arr) + 1 for end in range(len(arr)): current_sum += arr[end]

예산

Python
5 months ago
money = [120, 110, 140, 150] allmoney = 485 answer = 0 count = len(money) average = allmoney / len(money) for i in range(len(money)): if money[i] <= average: allmoney -= money[i] count -= 1

그룹 단어 체커

Python
5 months ago
n = int(input()) count = 0 for i in range(n): word = input().strip() seen = set() ans = '' grop = 1 for ch in word:

카드 (Queue)

Python
5 months ago
from collections import deque N = int(input()) cards = deque(range(1, N + 1)) while len(cards) > 1: cards.popleft() cards.append(cards.popleft()) print(cards[0])

크게 만들기

Python
5 months ago
number = "1924" k = 2 stack = [] for digit in number: while stack and k > 0 and stack[-1] < digit: stack.pop() k -= 1 stack.append(digit)

보석 도둑

Python
5 months ago
jewel = [(10, 100), (15, 200), (20, 150)] weight = 25 max_value = 0 for i in range(len(jewel)): total_w = 0 total_v = 0 for j in range(i, len(jewel)): total_w += jewel[j][0]

통계학

Python
5 months ago
lst = [1, 3, 8, 2, 2, 4, 7, 9, 1, 2] mid = len(lst) // 2 total = 0 ans = {} for i in lst: total += i for i in lst: if i in ans:

회의실 배정

Python
5 months ago
meetings = [(1,4), (3,5), (0,6), (5,7), (3,8)] meetings.sort(key=lambda x: x[1]) count = 0 end_time = 0 for start,end in meetings: if start >= end_time: count += 1

스위치 켜고 끄기

Python
5 months ago
Switches = [0, 1, 0, 1, 0, 0, 0, 1] Orders = [('남', 3)] num = Orders[0][1] if Orders[0][0] == '남': for i in range(len(Switches)): if (i + 1) % num == 0: Switches[i] = 1 - Switches[i] else: center = num - 1

수열의 구간 합(2)

Python
5 months ago
arr = [3, -2, -4, -9, 0, 3, 7, 13, 8, -3] max = 0 K = 3 for x in range(len(arr)-K+1): if max < sum(arr[x:x+K-1]): max = sum(arr[x:x+K-1]) print(max)

두 수의 합

Python
5 months ago
from itertools import combinations K = 10 arr = [1, 2, 3, 5, 7, 9] count = 0 for combo in combinations(arr,2): if sum(combo) == K: count += 1 print(count)

약수

Python
5 months ago
divisors = [4, 2] divisors.sort() N = divisors[0] * divisors[-1] print(N)

방 배정

Python
5 months ago
import math students = [("여", 1), ("여", 1), ("남", 1), ("남", 2), ("여", 2)] K = 2 count = 0 result = {} for x in students: result[x] = result.get(x,0)+1

일곱 난쟁이(combo)

Python
5 months ago
from itertools import combinations arr = [20, 7, 23, 19, 10, 15, 25, 8, 13] temp = [] for combo in combinations(arr,7): if sum(combo) == 100: temp = list(combo) print(temp)