Skip to content

Instantly share code, notes, and snippets.

View inspirit941's full-sized avatar

Donggeon Lee inspirit941

View GitHub Profile
from collections import defaultdict
from itertools import combinations_with_replacement, permutations
import heapq
import math
# 대기열에 n명의 상담원이 있을 때, wait time 총량 계산
def waiting_time(waitings, n):
total_time = 0
counsel_list = []
for _ in range(n):
import math
def solution(target):
# dp 문제.
# dp[i][0] = i점을 맞출 때 던질 수 있는 최소한의 다트 수
# dp[i][1] = 그때 싱글 / 불 맞춘 횟수
dp = [[math.inf, 0] for _ in range(target+1)]
dp[0][0] = 0
for i in range(1, target+1):
# 20까지를 기준으로
for j in range(1, 21):
from collections import deque, defaultdict
def bfs(nodes, start, end, visited, tables):
visited.add(start)
queue = deque([(start, 0)])
while queue:
node, cnt = queue.popleft()
if node in end:
tables[node] = cnt
for _next in nodes[node]:
from collections import deque
def check(cards, candidates, target):
for card in cards:
# 새로 들어온 카드를 써서 낼 수 있는 경우
if target - card in candidates:
candidates.remove(target-card)
cards.remove(card)
return True
return False
from collections import deque
def bfs(maps, start, end):
visited = set()
visited.add(start)
dirs = [(0,1),(0,-1),(1,0),(-1,0)]
queue = deque([start])
while queue:
y, x, cnt = queue.popleft()
if maps[y][x] == end:
def solution(targets):
targets = sorted(targets, key=(lambda x: (x[0], x[1])))
# 겹치는 구간을 최대한 찾되, 더 이상 겹치는 구간이 없어지면 포를 쏴야만 한다.
start, end = targets[0][0], targets[0][1]
answer = 1
for idx in range(1, len(targets)):
# 겹치는 범위가 없다면, answer ++ 한 뒤 start, end 초기화한다
if end <= targets[idx][0]:
answer += 1
start, end = targets[idx][0], targets[idx][1]
import sys
from collections import defaultdict
sys.setrecursionlimit(10 ** 6)
def solution(nodes, edges):
# root가 짝수 = root가 아니면 역짝수
# root가 홀수 = root가 아니면 역홀수
# root가 역짝수 = root가 아니면 짝수
# root가 역홀수 = root가 아니면 홀수
# 홀짝 트리 => root만 홀짝이고, 나머지는 전부 역홀짝이어야 한다.
import math
def solution(n, bans):
# 26 기준으로
# 1 ~ 26 = 1글자 'a'~ => n // 26 = 0인 것
# 26+1 ~ 26*2 = 2글자 'aa' ~ n // 26 = 1인 것
# 26*2+1 ~ 26*3 = 2글자 'ba' ~
# 26*25 ~ 26*26 = 2글자 끝
# 26*26+1 ~ ... 3글자 'aaa'...
# 26진수?
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'organizingContainers' function below.
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'pairs' function below.